authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-08-04 17:26:02-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-08-04 17:26:02-07:00
log54b67c20259f697f1e0c4532a5ee7e5d3f01eb1e
treed91b41ddd5dd4b9b941691722ce6427b3b82fe59
parent16513fee6c9c229e40f5abd82220a6f30e8e2180

libcxx: update from LLVM 10 to 11rc1


68 files changed, 4215 insertions(+), 1565 deletions(-)

lib/libcxx/include/__bit_reference+15
......@@ -1122,6 +1122,21 @@ public:
11221122 __bit_iterator(const __type_for_copy_to_const& __it) _NOEXCEPT
11231123 : __seg_(__it.__seg_), __ctz_(__it.__ctz_) {}
11241124
1125 // The non-const __bit_iterator has historically had a non-trivial
1126 // copy constructor (as a quirk of its construction). We need to maintain
1127 // this for ABI purposes.
1128 using __type_for_abi_non_trivial_copy_ctor =
1129 _If<!_IsConst, __bit_iterator, struct __private_nat>;
1130
1131 _LIBCPP_INLINE_VISIBILITY
1132 __bit_iterator(__type_for_abi_non_trivial_copy_ctor const& __it) _NOEXCEPT
1133 : __seg_(__it.__seg_), __ctz_(__it.__ctz_) {}
1134
1135 // Always declare the copy assignment operator since the implicit declaration
1136 // is deprecated.
1137 _LIBCPP_INLINE_VISIBILITY
1138 __bit_iterator& operator=(__bit_iterator const&) = default;
1139
11251140 _LIBCPP_INLINE_VISIBILITY reference operator*() const _NOEXCEPT
11261141 {return reference(__seg_, __storage_type(1) << __ctz_);}
11271142
lib/libcxx/include/__config+71-42
......@@ -32,7 +32,7 @@
3232# define _GNUC_VER_NEW 0
3333#endif
3434
35#define _LIBCPP_VERSION 10000
35#define _LIBCPP_VERSION 11000
3636
3737#ifndef _LIBCPP_ABI_VERSION
3838# define _LIBCPP_ABI_VERSION 1
......@@ -102,6 +102,9 @@
102102# define _LIBCPP_ABI_OPTIMIZED_FUNCTION
103103// All the regex constants must be distinct and nonzero.
104104# define _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO
105// Re-worked external template instantiations for std::string with a focus on
106// performance and fast-path inlining.
107# define _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION
105108#elif _LIBCPP_ABI_VERSION == 1
106109# if !defined(_LIBCPP_OBJECT_FORMAT_COFF)
107110// Enable compiling copies of now inline methods into the dylib to support
......@@ -395,12 +398,12 @@
395398
396399#if defined(_LIBCPP_COMPILER_CLANG)
397400
398// _LIBCPP_ALTERNATE_STRING_LAYOUT is an old name for
399// _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT left here for backward compatibility.
400#if (defined(__APPLE__) && !defined(__i386__) && !defined(__x86_64__) && \
401 (!defined(__arm__) || __ARM_ARCH_7K__ >= 2)) || \
402 defined(_LIBCPP_ALTERNATE_STRING_LAYOUT)
403#define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
401#if defined(_LIBCPP_ALTERNATE_STRING_LAYOUT)
402# error _LIBCPP_ALTERNATE_STRING_LAYOUT is deprecated, please use _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT instead
403#endif
404#if defined(__APPLE__) && !defined(__i386__) && !defined(__x86_64__) && \
405 (!defined(__arm__) || __ARM_ARCH_7K__ >= 2)
406# define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
404407#endif
405408
406409#if __has_feature(cxx_alignas)
......@@ -416,12 +419,8 @@ typedef __char16_t char16_t;
416419typedef __char32_t char32_t;
417420#endif
418421
419#if !(__has_feature(cxx_exceptions)) && !defined(_LIBCPP_NO_EXCEPTIONS)
420#define _LIBCPP_NO_EXCEPTIONS
421#endif
422
423#if !(__has_feature(cxx_rtti)) && !defined(_LIBCPP_NO_RTTI)
424#define _LIBCPP_NO_RTTI
422#if !__has_feature(cxx_exceptions)
423# define _LIBCPP_NO_EXCEPTIONS
425424#endif
426425
427426#if !(__has_feature(cxx_strong_enums))
......@@ -467,6 +466,14 @@ typedef __char32_t char32_t;
467466#define _LIBCPP_HAS_OBJC_ARC_WEAK
468467#endif
469468
469#if __has_extension(blocks)
470# define _LIBCPP_HAS_EXTENSION_BLOCKS
471#endif
472
473#if defined(_LIBCPP_HAS_EXTENSION_BLOCKS) && defined(__APPLE__)
474# define _LIBCPP_HAS_BLOCKS_RUNTIME
475#endif
476
470477#if !(__has_feature(cxx_relaxed_constexpr))
471478#define _LIBCPP_HAS_NO_CXX14_CONSTEXPR
472479#endif
......@@ -492,6 +499,10 @@ typedef __char32_t char32_t;
492499#define _LIBCPP_COMPILER_HAS_BUILTIN_LAUNDER
493500#endif
494501
502#if __has_builtin(__builtin_constant_p)
503#define _LIBCPP_COMPILER_HAS_BUILTIN_CONSTANT_P
504#endif
505
495506#if !__is_identifier(__has_unique_object_representations)
496507#define _LIBCPP_HAS_UNIQUE_OBJECT_REPRESENTATIONS
497508#endif
......@@ -513,8 +524,8 @@ typedef __char32_t char32_t;
513524
514525#define _LIBCPP_NORETURN __attribute__((noreturn))
515526
516#if !__EXCEPTIONS && !defined(_LIBCPP_NO_EXCEPTIONS)
517#define _LIBCPP_NO_EXCEPTIONS
527#if !__EXCEPTIONS
528# define _LIBCPP_NO_EXCEPTIONS
518529#endif
519530
520531// Determine if GCC supports relaxed constexpr
......@@ -533,9 +544,7 @@ typedef __char32_t char32_t;
533544
534545#if _GNUC_VER >= 700
535546#define _LIBCPP_COMPILER_HAS_BUILTIN_LAUNDER
536#endif
537
538#if _GNUC_VER >= 700
547#define _LIBCPP_COMPILER_HAS_BUILTIN_CONSTANT_P
539548#define _LIBCPP_HAS_UNIQUE_OBJECT_REPRESENTATIONS
540549#endif
541550
......@@ -745,14 +754,14 @@ typedef __char32_t char32_t;
745754# endif
746755#endif
747756
748#ifndef _LIBCPP_HAS_MERGED_TYPEINFO_NAMES_DEFAULT
749# ifdef _LIBCPP_OBJECT_FORMAT_COFF // Windows binaries can't merge typeinfos.
750# define _LIBCPP_HAS_MERGED_TYPEINFO_NAMES_DEFAULT 0
751#else
752// TODO: This isn't strictly correct on ELF platforms due to llvm.org/PR37398
753// And we should consider defaulting to OFF.
754# define _LIBCPP_HAS_MERGED_TYPEINFO_NAMES_DEFAULT 1
755#endif
757#ifndef _LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION
758# ifdef _LIBCPP_OBJECT_FORMAT_COFF // Windows binaries can't merge typeinfos.
759# define _LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION 2
760# else
761 // TODO: This isn't strictly correct on ELF platforms due to llvm.org/PR37398
762 // And we should consider defaulting to OFF.
763# define _LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION 1
764# endif
756765#endif
757766
758767#ifndef _LIBCPP_HIDE_FROM_ABI
......@@ -901,6 +910,10 @@ typedef unsigned int char32_t;
901910#define _LIBCPP_EXTERN_TEMPLATE2(...) extern template __VA_ARGS__;
902911#endif
903912
913#ifndef _LIBCPP_EXTERN_TEMPLATE_DEFINE
914#define _LIBCPP_EXTERN_TEMPLATE_DEFINE(...) template __VA_ARGS__;
915#endif
916
904917#if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCPP_MSVCRT_LIKE) || \
905918 defined(__sun__) || defined(__NetBSD__) || defined(__CloudABI__)
906919#define _LIBCPP_LOCALE__L_EXTENSIONS 1
......@@ -1092,17 +1105,12 @@ _LIBCPP_FUNC_VIS extern "C" void __sanitizer_annotate_contiguous_container(
10921105#endif
10931106
10941107// Try to find out if RTTI is disabled.
1095// g++ and cl.exe have RTTI on by default and define a macro when it is.
1096// g++ only defines the macro in 4.3.2 and onwards.
1097#if !defined(_LIBCPP_NO_RTTI)
1098# if defined(__GNUC__) && \
1099 ((__GNUC__ >= 5) || \
1100 (__GNUC__ == 4 && (__GNUC_MINOR__ >= 3 || __GNUC_PATCHLEVEL__ >= 2))) && \
1101 !defined(__GXX_RTTI)
1102# define _LIBCPP_NO_RTTI
1103# elif defined(_LIBCPP_COMPILER_MSVC) && !defined(_CPPRTTI)
1104# define _LIBCPP_NO_RTTI
1105# endif
1108#if defined(_LIBCPP_COMPILER_CLANG) && !__has_feature(cxx_rtti)
1109# define _LIBCPP_NO_RTTI
1110#elif defined(__GNUC__) && !defined(__GXX_RTTI)
1111# define _LIBCPP_NO_RTTI
1112#elif defined(_LIBCPP_COMPILER_MSVC) && !defined(_CPPRTTI)
1113# define _LIBCPP_NO_RTTI
11061114#endif
11071115
11081116#ifndef _LIBCPP_WEAK
......@@ -1125,7 +1133,8 @@ _LIBCPP_FUNC_VIS extern "C" void __sanitizer_annotate_contiguous_container(
11251133 (defined(__MINGW32__) && __has_include(<pthread.h>))
11261134# define _LIBCPP_HAS_THREAD_API_PTHREAD
11271135# elif defined(__Fuchsia__)
1128# define _LIBCPP_HAS_THREAD_API_C11
1136 // TODO(44575): Switch to C11 thread API when possible.
1137# define _LIBCPP_HAS_THREAD_API_PTHREAD
11291138# elif defined(_LIBCPP_WIN32API)
11301139# define _LIBCPP_HAS_THREAD_API_WIN32
11311140# else
......@@ -1360,6 +1369,7 @@ _LIBCPP_FUNC_VIS extern "C" void __sanitizer_annotate_contiguous_container(
13601369
13611370// Decide whether to use availability macros.
13621371#if !defined(_LIBCPP_BUILDING_LIBRARY) && \
1372 !defined(_LIBCXXABI_BUILDING_LIBRARY) && \
13631373 !defined(_LIBCPP_DISABLE_AVAILABILITY) && \
13641374 __has_feature(attribute_availability_with_strict) && \
13651375 __has_feature(attribute_availability_in_templates) && \
......@@ -1377,10 +1387,10 @@ _LIBCPP_FUNC_VIS extern "C" void __sanitizer_annotate_contiguous_container(
13771387 __attribute__((availability(tvos,strict,introduced=10.0))) \
13781388 __attribute__((availability(watchos,strict,introduced=3.0)))
13791389# define _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS \
1380 __attribute__((availability(macosx,strict,introduced=10.14))) \
1381 __attribute__((availability(ios,strict,introduced=12.0))) \
1382 __attribute__((availability(tvos,strict,introduced=12.0))) \
1383 __attribute__((availability(watchos,strict,introduced=5.0)))
1390 __attribute__((availability(macosx,strict,introduced=10.13))) \
1391 __attribute__((availability(ios,strict,introduced=11.0))) \
1392 __attribute__((availability(tvos,strict,introduced=11.0))) \
1393 __attribute__((availability(watchos,strict,introduced=4.0)))
13841394# define _LIBCPP_AVAILABILITY_BAD_VARIANT_ACCESS \
13851395 _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS
13861396# define _LIBCPP_AVAILABILITY_BAD_ANY_CAST \
......@@ -1421,6 +1431,10 @@ _LIBCPP_FUNC_VIS extern "C" void __sanitizer_annotate_contiguous_container(
14211431 _Pragma("clang attribute pop") \
14221432 _Pragma("clang attribute pop") \
14231433 _Pragma("clang attribute pop")
1434# define _LIBCPP_AVAILABILITY_TO_CHARS \
1435 _LIBCPP_AVAILABILITY_FILESYSTEM
1436# define _LIBCPP_AVAILABILITY_SYNC \
1437 __attribute__((unavailable))
14241438#else
14251439# define _LIBCPP_AVAILABILITY_SHARED_MUTEX
14261440# define _LIBCPP_AVAILABILITY_BAD_VARIANT_ACCESS
......@@ -1435,6 +1449,8 @@ _LIBCPP_FUNC_VIS extern "C" void __sanitizer_annotate_contiguous_container(
14351449# define _LIBCPP_AVAILABILITY_FILESYSTEM
14361450# define _LIBCPP_AVAILABILITY_FILESYSTEM_PUSH
14371451# define _LIBCPP_AVAILABILITY_FILESYSTEM_POP
1452# define _LIBCPP_AVAILABILITY_TO_CHARS
1453# define _LIBCPP_AVAILABILITY_SYNC
14381454#endif
14391455
14401456// Define availability that depends on _LIBCPP_NO_EXCEPTIONS.
......@@ -1518,6 +1534,19 @@ _LIBCPP_FUNC_VIS extern "C" void __sanitizer_annotate_contiguous_container(
15181534# define _LIBCPP_FOPEN_CLOEXEC_MODE
15191535#endif
15201536
1537#ifdef _LIBCPP_COMPILER_HAS_BUILTIN_CONSTANT_P
1538#define _LIBCPP_BUILTIN_CONSTANT_P(x) __builtin_constant_p(x)
1539#else
1540#define _LIBCPP_BUILTIN_CONSTANT_P(x) false
1541#endif
1542
1543// Support for _FILE_OFFSET_BITS=64 landed gradually in Android, so the full set
1544// of functions used in cstdio may not be available for low API levels when
1545// using 64-bit file offsets on LP32.
1546#if defined(__BIONIC__) && defined(__USE_FILE_OFFSET64) && __ANDROID_API__ < 24
1547#define _LIBCPP_HAS_NO_FGETPOS_FSETPOS
1548#endif
1549
15211550#endif // __cplusplus
15221551
15231552#endif // _LIBCPP_CONFIG
lib/libcxx/include/__config_site.in+3-1
......@@ -27,7 +27,9 @@
2727#cmakedefine _LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL
2828#cmakedefine _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS
2929#cmakedefine _LIBCPP_NO_VCRUNTIME
30#cmakedefine01 _LIBCPP_HAS_MERGED_TYPEINFO_NAMES_DEFAULT
30#ifndef _LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION
31#cmakedefine _LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION @_LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION@
32#endif
3133#cmakedefine _LIBCPP_ABI_NAMESPACE @_LIBCPP_ABI_NAMESPACE@
3234#cmakedefine _LIBCPP_HAS_PARALLEL_ALGORITHMS
3335
lib/libcxx/include/__functional_base+2-2
......@@ -522,7 +522,7 @@ inline _LIBCPP_INLINE_VISIBILITY
522522reference_wrapper<_Tp>
523523ref(reference_wrapper<_Tp> __t) _NOEXCEPT
524524{
525 return ref(__t.get());
525 return _VSTD::ref(__t.get());
526526}
527527
528528template <class _Tp>
......@@ -538,7 +538,7 @@ inline _LIBCPP_INLINE_VISIBILITY
538538reference_wrapper<const _Tp>
539539cref(reference_wrapper<_Tp> __t) _NOEXCEPT
540540{
541 return cref(__t.get());
541 return _VSTD::cref(__t.get());
542542}
543543
544544#ifndef _LIBCPP_CXX03_LANG
lib/libcxx/include/__libcpp_version+1-1
......@@ -1 +1 @@
110000
111000
lib/libcxx/include/__locale+6
......@@ -496,7 +496,13 @@ public:
496496 static const mask punct = 1<<7;
497497 static const mask xdigit = 1<<8;
498498 static const mask blank = 1<<9;
499#if defined(__BIONIC__)
500 // Historically this was a part of regex_traits rather than ctype_base. The
501 // historical value of the constant is preserved for ABI compatibility.
502 static const mask __regex_word = 0x8000;
503#else
499504 static const mask __regex_word = 1<<10;
505#endif // defined(__BIONIC__)
500506#endif
501507 static const mask alnum = alpha | digit;
502508 static const mask graph = alnum | punct;
lib/libcxx/include/__string+117
......@@ -70,6 +70,123 @@ _LIBCPP_PUSH_MACROS
7070
7171_LIBCPP_BEGIN_NAMESPACE_STD
7272
73// The the extern template ABI lists are kept outside of <string> to improve the
74// readability of that header.
75
76// The extern template ABI lists are kept outside of <string> to improve the
77// readability of that header. We maintain 2 ABI lists:
78// - _LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST
79// - _LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST
80// As the name implies, the ABI lists define the V1 (Stable) and unstable ABI.
81//
82// For unstable, we may explicitly remove function that are external in V1,
83// and add (new) external functions to better control inlining and compiler
84// optimization opportunities.
85//
86// For stable, the ABI list should rarely change, except for adding new
87// functions supporting new c++ version / API changes. Typically entries
88// must never be removed from the stable list.
89#define _LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_Func, _CharType) \
90 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::replace(size_type, size_type, value_type const*, size_type)) \
91 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::rfind(value_type const*, size_type, size_type) const) \
92 _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::__init(value_type const*, size_type, size_type)) \
93 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::basic_string(basic_string const&)) \
94 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::replace(size_type, size_type, value_type const*)) \
95 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::basic_string(basic_string const&, std::allocator<_CharType> const&)) \
96 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::find_last_not_of(value_type const*, size_type, size_type) const) \
97 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::~basic_string()) \
98 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::find_first_not_of(value_type const*, size_type, size_type) const) \
99 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::insert(size_type, size_type, value_type)) \
100 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::operator=(value_type)) \
101 _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::__init(value_type const*, size_type)) \
102 _Func(_LIBCPP_FUNC_VIS const _CharType& basic_string<_CharType>::at(size_type) const) \
103 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::insert(size_type, value_type const*, size_type)) \
104 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::find_first_of(value_type const*, size_type, size_type) const) \
105 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::replace(size_type, size_type, size_type, value_type)) \
106 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::assign(value_type const*, size_type)) \
107 _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::reserve(size_type)) \
108 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::append(value_type const*, size_type)) \
109 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::assign(basic_string const&, size_type, size_type)) \
110 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::copy(value_type*, size_type, size_type) const) \
111 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::basic_string(basic_string const&, size_type, size_type, std::allocator<_CharType> const&)) \
112 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::find(value_type, size_type) const) \
113 _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::__init(size_type, value_type)) \
114 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::insert(size_type, value_type const*)) \
115 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::find_last_of(value_type const*, size_type, size_type) const) \
116 _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::__grow_by(size_type, size_type, size_type, size_type, size_type, size_type)) \
117 _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::__grow_by_and_replace(size_type, size_type, size_type, size_type, size_type, size_type, value_type const*)) \
118 _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::push_back(value_type)) \
119 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::append(size_type, value_type)) \
120 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::rfind(value_type, size_type) const) \
121 _Func(_LIBCPP_FUNC_VIS const basic_string<_CharType>::size_type basic_string<_CharType>::npos) \
122 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::assign(size_type, value_type)) \
123 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::erase(size_type, size_type)) \
124 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::append(basic_string const&, size_type, size_type)) \
125 _Func(_LIBCPP_FUNC_VIS int basic_string<_CharType>::compare(value_type const*) const) \
126 _Func(_LIBCPP_FUNC_VIS int basic_string<_CharType>::compare(size_type, size_type, value_type const*) const) \
127 _Func(_LIBCPP_FUNC_VIS _CharType& basic_string<_CharType>::at(size_type)) \
128 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::assign(value_type const*)) \
129 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::find(value_type const*, size_type, size_type) const) \
130 _Func(_LIBCPP_FUNC_VIS int basic_string<_CharType>::compare(size_type, size_type, basic_string const&, size_type, size_type) const) \
131 _Func(_LIBCPP_FUNC_VIS int basic_string<_CharType>::compare(size_type, size_type, value_type const*, size_type) const) \
132 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::operator=(basic_string const&)) \
133 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::append(value_type const*)) \
134 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::replace(size_type, size_type, basic_string const&, size_type, size_type)) \
135 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::iterator basic_string<_CharType>::insert(basic_string::const_iterator, value_type)) \
136 _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::resize(size_type, value_type)) \
137 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::insert(size_type, basic_string const&, size_type, size_type))
138
139#define _LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_Func, _CharType) \
140 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::replace(size_type, size_type, value_type const*, size_type)) \
141 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::rfind(value_type const*, size_type, size_type) const) \
142 _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::__init(value_type const*, size_type, size_type)) \
143 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::replace(size_type, size_type, value_type const*)) \
144 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::find_last_not_of(value_type const*, size_type, size_type) const) \
145 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::~basic_string()) \
146 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::find_first_not_of(value_type const*, size_type, size_type) const) \
147 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::insert(size_type, size_type, value_type)) \
148 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::operator=(value_type)) \
149 _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::__init(value_type const*, size_type)) \
150 _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::__init_copy_ctor_external(value_type const*, size_type)) \
151 _Func(_LIBCPP_FUNC_VIS const _CharType& basic_string<_CharType>::at(size_type) const) \
152 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::insert(size_type, value_type const*, size_type)) \
153 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::find_first_of(value_type const*, size_type, size_type) const) \
154 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::replace(size_type, size_type, size_type, value_type)) \
155 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::__assign_external(value_type const*, size_type)) \
156 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::__assign_external(value_type const*)) \
157 _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::reserve(size_type)) \
158 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::append(value_type const*, size_type)) \
159 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::assign(basic_string const&, size_type, size_type)) \
160 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::copy(value_type*, size_type, size_type) const) \
161 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::basic_string(basic_string const&, size_type, size_type, std::allocator<_CharType> const&)) \
162 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::find(value_type, size_type) const) \
163 _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::__init(size_type, value_type)) \
164 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::insert(size_type, value_type const*)) \
165 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::find_last_of(value_type const*, size_type, size_type) const) \
166 _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::__grow_by(size_type, size_type, size_type, size_type, size_type, size_type)) \
167 _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::__grow_by_and_replace(size_type, size_type, size_type, size_type, size_type, size_type, value_type const*)) \
168 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::__assign_no_alias<false>(value_type const*, size_type)) \
169 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::__assign_no_alias<true>(value_type const*, size_type)) \
170 _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::push_back(value_type)) \
171 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::append(size_type, value_type)) \
172 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::rfind(value_type, size_type) const) \
173 _Func(_LIBCPP_FUNC_VIS const basic_string<_CharType>::size_type basic_string<_CharType>::npos) \
174 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::assign(size_type, value_type)) \
175 _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::__erase_external_with_move(size_type, size_type)) \
176 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::append(basic_string const&, size_type, size_type)) \
177 _Func(_LIBCPP_FUNC_VIS int basic_string<_CharType>::compare(value_type const*) const) \
178 _Func(_LIBCPP_FUNC_VIS int basic_string<_CharType>::compare(size_type, size_type, value_type const*) const) \
179 _Func(_LIBCPP_FUNC_VIS _CharType& basic_string<_CharType>::at(size_type)) \
180 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::find(value_type const*, size_type, size_type) const) \
181 _Func(_LIBCPP_FUNC_VIS int basic_string<_CharType>::compare(size_type, size_type, basic_string const&, size_type, size_type) const) \
182 _Func(_LIBCPP_FUNC_VIS int basic_string<_CharType>::compare(size_type, size_type, value_type const*, size_type) const) \
183 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::append(value_type const*)) \
184 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::replace(size_type, size_type, basic_string const&, size_type, size_type)) \
185 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::iterator basic_string<_CharType>::insert(basic_string::const_iterator, value_type)) \
186 _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::resize(size_type, value_type)) \
187 _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::insert(size_type, basic_string const&, size_type, size_type))
188
189
73190// char_traits
74191
75192template <class _CharT>
lib/libcxx/include/__threading_support+111
......@@ -26,6 +26,12 @@
2626#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
2727# include <pthread.h>
2828# include <sched.h>
29# ifdef __APPLE__
30# define _LIBCPP_NO_NATIVE_SEMAPHORES
31# endif
32# ifndef _LIBCPP_NO_NATIVE_SEMAPHORES
33# include <semaphore.h>
34# endif
2935#elif defined(_LIBCPP_HAS_THREAD_API_C11)
3036# include <threads.h>
3137#endif
......@@ -65,6 +71,12 @@ typedef pthread_mutex_t __libcpp_recursive_mutex_t;
6571typedef pthread_cond_t __libcpp_condvar_t;
6672#define _LIBCPP_CONDVAR_INITIALIZER PTHREAD_COND_INITIALIZER
6773
74#ifndef _LIBCPP_NO_NATIVE_SEMAPHORES
75// Semaphore
76typedef sem_t __libcpp_semaphore_t;
77# define _LIBCPP_SEMAPHORE_MAX SEM_VALUE_MAX
78#endif
79
6880// Execute once
6981typedef pthread_once_t __libcpp_exec_once_flag;
7082#define _LIBCPP_EXEC_ONCE_INITIALIZER PTHREAD_ONCE_INIT
......@@ -127,6 +139,9 @@ typedef void* __libcpp_recursive_mutex_t[5];
127139typedef void* __libcpp_condvar_t;
128140#define _LIBCPP_CONDVAR_INITIALIZER 0
129141
142// Semaphore
143typedef void* __libcpp_semaphore_t;
144
130145// Execute Once
131146typedef void* __libcpp_exec_once_flag;
132147#define _LIBCPP_EXEC_ONCE_INITIALIZER 0
......@@ -191,6 +206,26 @@ int __libcpp_condvar_timedwait(__libcpp_condvar_t *__cv, __libcpp_mutex_t *__m,
191206_LIBCPP_THREAD_ABI_VISIBILITY
192207int __libcpp_condvar_destroy(__libcpp_condvar_t* __cv);
193208
209#ifndef _LIBCPP_NO_NATIVE_SEMAPHORES
210
211// Semaphore
212_LIBCPP_THREAD_ABI_VISIBILITY
213bool __libcpp_semaphore_init(__libcpp_semaphore_t* __sem, int __init);
214
215_LIBCPP_THREAD_ABI_VISIBILITY
216bool __libcpp_semaphore_destroy(__libcpp_semaphore_t* __sem);
217
218_LIBCPP_THREAD_ABI_VISIBILITY
219bool __libcpp_semaphore_post(__libcpp_semaphore_t* __sem);
220
221_LIBCPP_THREAD_ABI_VISIBILITY
222bool __libcpp_semaphore_wait(__libcpp_semaphore_t* __sem);
223
224_LIBCPP_THREAD_ABI_VISIBILITY
225bool __libcpp_semaphore_wait_timed(__libcpp_semaphore_t* __sem, chrono::nanoseconds const& __ns);
226
227#endif // _LIBCPP_NO_NATIVE_SEMAPHORES
228
194229// Execute once
195230_LIBCPP_THREAD_ABI_VISIBILITY
196231int __libcpp_execute_once(__libcpp_exec_once_flag *flag,
......@@ -242,9 +277,52 @@ int __libcpp_tls_set(__libcpp_tls_key __key, void *__p);
242277
243278#endif // !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
244279
280struct __libcpp_timed_backoff_policy {
281 _LIBCPP_THREAD_ABI_VISIBILITY
282 bool operator()(chrono::nanoseconds __elapsed) const;
283};
284
285inline _LIBCPP_INLINE_VISIBILITY
286bool __libcpp_timed_backoff_policy::operator()(chrono::nanoseconds __elapsed) const
287{
288 if(__elapsed > chrono::milliseconds(128))
289 __libcpp_thread_sleep_for(chrono::milliseconds(8));
290 else if(__elapsed > chrono::microseconds(64))
291 __libcpp_thread_sleep_for(__elapsed / 2);
292 else if(__elapsed > chrono::microseconds(4))
293 __libcpp_thread_yield();
294 else
295 ; // poll
296 return false;
297}
298
299static _LIBCPP_CONSTEXPR const int __libcpp_polling_count = 64;
300
301template<class _Fn, class _BFn>
302_LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
303bool __libcpp_thread_poll_with_backoff(
304 _Fn && __f, _BFn && __bf, chrono::nanoseconds __max_elapsed = chrono::nanoseconds::zero())
305{
306 auto const __start = chrono::high_resolution_clock::now();
307 for(int __count = 0;;) {
308 if(__f())
309 return true; // _Fn completion means success
310 if(__count < __libcpp_polling_count) {
311 __count += 1;
312 continue;
313 }
314 chrono::nanoseconds const __elapsed = chrono::high_resolution_clock::now() - __start;
315 if(__max_elapsed != chrono::nanoseconds::zero() && __max_elapsed < __elapsed)
316 return false; // timeout failure
317 if(__bf(__elapsed))
318 return false; // _BFn completion means failure
319 }
320}
321
245322#if (!defined(_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL) || \
246323 defined(_LIBCPP_BUILDING_THREAD_LIBRARY_EXTERNAL))
247324
325
248326namespace __thread_detail {
249327
250328inline __libcpp_timespec_t __convert_to_timespec(const chrono::nanoseconds& __ns)
......@@ -364,6 +442,38 @@ int __libcpp_condvar_destroy(__libcpp_condvar_t *__cv)
364442 return pthread_cond_destroy(__cv);
365443}
366444
445#ifndef _LIBCPP_NO_NATIVE_SEMAPHORES
446
447// Semaphore
448bool __libcpp_semaphore_init(__libcpp_semaphore_t* __sem, int __init)
449{
450 return sem_init(__sem, 0, __init) == 0;
451}
452
453bool __libcpp_semaphore_destroy(__libcpp_semaphore_t* __sem)
454{
455 return sem_destroy(__sem) == 0;
456}
457
458bool __libcpp_semaphore_post(__libcpp_semaphore_t* __sem)
459{
460 return sem_post(__sem) == 0;
461}
462
463bool __libcpp_semaphore_wait(__libcpp_semaphore_t* __sem)
464{
465 return sem_wait(__sem) == 0;
466}
467
468bool __libcpp_semaphore_wait_timed(__libcpp_semaphore_t* __sem, chrono::nanoseconds const& __ns)
469{
470 auto const __abs_time = chrono::system_clock::now().time_since_epoch() + __ns;
471 __libcpp_timespec_t __ts = __thread_detail::__convert_to_timespec(__abs_time);
472 return sem_timedwait(__sem, &__ts) == 0;
473}
474
475#endif //_LIBCPP_NO_NATIVE_SEMAPHORES
476
367477// Execute once
368478int __libcpp_execute_once(__libcpp_exec_once_flag *flag,
369479 void (*init_routine)()) {
......@@ -600,6 +710,7 @@ int __libcpp_tls_set(__libcpp_tls_key __key, void *__p)
600710
601711#endif
602712
713
603714#endif // !_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL || _LIBCPP_BUILDING_THREAD_LIBRARY_EXTERNAL
604715
605716class _LIBCPP_TYPE_VIS thread;
lib/libcxx/include/array+144-101
......@@ -32,24 +32,24 @@ struct array
3232 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
3333
3434 // No explicit construct/copy/destroy for aggregate type
35 void fill(const T& u);
36 void swap(array& a) noexcept(is_nothrow_swappable_v<T>);
35 void fill(const T& u); // constexpr in C++20
36 void swap(array& a) noexcept(is_nothrow_swappable_v<T>); // constexpr in C++20
3737
3838 // iterators:
39 iterator begin() noexcept;
40 const_iterator begin() const noexcept;
41 iterator end() noexcept;
42 const_iterator end() const noexcept;
39 iterator begin() noexcept; // constexpr in C++17
40 const_iterator begin() const noexcept; // constexpr in C++17
41 iterator end() noexcept; // constexpr in C++17
42 const_iterator end() const noexcept; // constexpr in C++17
4343
44 reverse_iterator rbegin() noexcept;
45 const_reverse_iterator rbegin() const noexcept;
46 reverse_iterator rend() noexcept;
47 const_reverse_iterator rend() const noexcept;
44 reverse_iterator rbegin() noexcept; // constexpr in C++17
45 const_reverse_iterator rbegin() const noexcept; // constexpr in C++17
46 reverse_iterator rend() noexcept; // constexpr in C++17
47 const_reverse_iterator rend() const noexcept; // constexpr in C++17
4848
49 const_iterator cbegin() const noexcept;
50 const_iterator cend() const noexcept;
51 const_reverse_iterator crbegin() const noexcept;
52 const_reverse_iterator crend() const noexcept;
49 const_iterator cbegin() const noexcept; // constexpr in C++17
50 const_iterator cend() const noexcept; // constexpr in C++17
51 const_reverse_iterator crbegin() const noexcept; // constexpr in C++17
52 const_reverse_iterator crend() const noexcept; // constexpr in C++17
5353
5454 // capacity:
5555 constexpr size_type size() const noexcept;
......@@ -57,46 +57,51 @@ struct array
5757 constexpr bool empty() const noexcept;
5858
5959 // element access:
60 reference operator[](size_type n);
61 const_reference operator[](size_type n) const; // constexpr in C++14
62 const_reference at(size_type n) const; // constexpr in C++14
63 reference at(size_type n);
64
65 reference front();
66 const_reference front() const; // constexpr in C++14
67 reference back();
68 const_reference back() const; // constexpr in C++14
69
70 T* data() noexcept;
71 const T* data() const noexcept;
60 reference operator[](size_type n); // constexpr in C++17
61 const_reference operator[](size_type n) const; // constexpr in C++14
62 reference at(size_type n); // constexpr in C++17
63 const_reference at(size_type n) const; // constexpr in C++14
64
65 reference front(); // constexpr in C++17
66 const_reference front() const; // constexpr in C++14
67 reference back(); // constexpr in C++17
68 const_reference back() const; // constexpr in C++14
69
70 T* data() noexcept; // constexpr in C++17
71 const T* data() const noexcept; // constexpr in C++17
7272};
7373
74 template <class T, class... U>
75 array(T, U...) -> array<T, 1 + sizeof...(U)>;
74template <class T, class... U>
75 array(T, U...) -> array<T, 1 + sizeof...(U)>; // C++17
7676
7777template <class T, size_t N>
78 bool operator==(const array<T,N>& x, const array<T,N>& y);
78 bool operator==(const array<T,N>& x, const array<T,N>& y); // constexpr in C++20
7979template <class T, size_t N>
80 bool operator!=(const array<T,N>& x, const array<T,N>& y);
80 bool operator!=(const array<T,N>& x, const array<T,N>& y); // constexpr in C++20
8181template <class T, size_t N>
82 bool operator<(const array<T,N>& x, const array<T,N>& y);
82 bool operator<(const array<T,N>& x, const array<T,N>& y); // constexpr in C++20
8383template <class T, size_t N>
84 bool operator>(const array<T,N>& x, const array<T,N>& y);
84 bool operator>(const array<T,N>& x, const array<T,N>& y); // constexpr in C++20
8585template <class T, size_t N>
86 bool operator<=(const array<T,N>& x, const array<T,N>& y);
86 bool operator<=(const array<T,N>& x, const array<T,N>& y); // constexpr in C++20
8787template <class T, size_t N>
88 bool operator>=(const array<T,N>& x, const array<T,N>& y);
88 bool operator>=(const array<T,N>& x, const array<T,N>& y); // constexpr in C++20
8989
9090template <class T, size_t N >
91 void swap(array<T,N>& x, array<T,N>& y) noexcept(noexcept(x.swap(y))); // C++17
91 void swap(array<T,N>& x, array<T,N>& y) noexcept(noexcept(x.swap(y))); // constexpr in C++20
92
93template <class T, size_t N>
94 constexpr array<remove_cv_t<T>, N> to_array(T (&a)[N]); // C++20
95template <class T, size_t N>
96 constexpr array<remove_cv_t<T>, N> to_array(T (&&a)[N]); // C++20
9297
9398template <class T> struct tuple_size;
9499template <size_t I, class T> struct tuple_element;
95100template <class T, size_t N> struct tuple_size<array<T, N>>;
96101template <size_t I, class T, size_t N> struct tuple_element<I, array<T, N>>;
97template <size_t I, class T, size_t N> T& get(array<T, N>&) noexcept; // constexpr in C++14
98template <size_t I, class T, size_t N> const T& get(const array<T, N>&) noexcept; // constexpr in C++14
99template <size_t I, class T, size_t N> T&& get(array<T, N>&&) noexcept; // constexpr in C++14
102template <size_t I, class T, size_t N> T& get(array<T, N>&) noexcept; // constexpr in C++14
103template <size_t I, class T, size_t N> const T& get(const array<T, N>&) noexcept; // constexpr in C++14
104template <size_t I, class T, size_t N> T&& get(array<T, N>&&) noexcept; // constexpr in C++14
100105template <size_t I, class T, size_t N> const T&& get(const array<T, N>&&) noexcept; // constexpr in C++14
101106
102107} // std
......@@ -143,13 +148,14 @@ struct _LIBCPP_TEMPLATE_VIS array
143148 _Tp __elems_[_Size];
144149
145150 // No explicit construct/copy/destroy for aggregate type
146 _LIBCPP_INLINE_VISIBILITY void fill(const value_type& __u) {
147 _VSTD::fill_n(__elems_, _Size, __u);
151 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
152 void fill(const value_type& __u) {
153 _VSTD::fill_n(data(), _Size, __u);
148154 }
149155
150 _LIBCPP_INLINE_VISIBILITY
156 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
151157 void swap(array& __a) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value) {
152 std::swap_ranges(__elems_, __elems_ + _Size, __a.__elems_);
158 std::swap_ranges(data(), data() + _Size, __a.data());
153159 }
154160
155161 // iterators:
......@@ -186,21 +192,38 @@ struct _LIBCPP_TEMPLATE_VIS array
186192 _LIBCPP_INLINE_VISIBILITY
187193 _LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT {return _Size;}
188194 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
189 _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT {return false; }
195 _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT {return _Size == 0;}
190196
191197 // element access:
192198 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
193 reference operator[](size_type __n) _NOEXCEPT {return __elems_[__n];}
199 reference operator[](size_type __n) _NOEXCEPT {
200 _LIBCPP_ASSERT(__n < _Size, "out-of-bounds access in std::array<T, N>");
201 return __elems_[__n];
202 }
194203 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
195 const_reference operator[](size_type __n) const _NOEXCEPT {return __elems_[__n];}
204 const_reference operator[](size_type __n) const _NOEXCEPT {
205 _LIBCPP_ASSERT(__n < _Size, "out-of-bounds access in std::array<T, N>");
206 return __elems_[__n];
207 }
196208
197 _LIBCPP_CONSTEXPR_AFTER_CXX14 reference at(size_type __n);
198 _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference at(size_type __n) const;
209 _LIBCPP_CONSTEXPR_AFTER_CXX14 reference at(size_type __n)
210 {
211 if (__n >= _Size)
212 __throw_out_of_range("array::at");
213 return __elems_[__n];
214 }
199215
200 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference front() _NOEXCEPT {return __elems_[0];}
201 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference front() const _NOEXCEPT {return __elems_[0];}
202 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference back() _NOEXCEPT {return __elems_[_Size - 1];}
203 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference back() const _NOEXCEPT {return __elems_[_Size - 1];}
216 _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference at(size_type __n) const
217 {
218 if (__n >= _Size)
219 __throw_out_of_range("array::at");
220 return __elems_[__n];
221 }
222
223 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference front() _NOEXCEPT {return (*this)[0];}
224 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference front() const _NOEXCEPT {return (*this)[0];}
225 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference back() _NOEXCEPT {return (*this)[_Size - 1];}
226 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference back() const _NOEXCEPT {return (*this)[_Size - 1];}
204227
205228 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
206229 value_type* data() _NOEXCEPT {return __elems_;}
......@@ -208,28 +231,6 @@ struct _LIBCPP_TEMPLATE_VIS array
208231 const value_type* data() const _NOEXCEPT {return __elems_;}
209232};
210233
211
212template <class _Tp, size_t _Size>
213_LIBCPP_CONSTEXPR_AFTER_CXX14
214typename array<_Tp, _Size>::reference
215array<_Tp, _Size>::at(size_type __n)
216{
217 if (__n >= _Size)
218 __throw_out_of_range("array::at");
219
220 return __elems_[__n];
221}
222
223template <class _Tp, size_t _Size>
224_LIBCPP_CONSTEXPR_AFTER_CXX11
225typename array<_Tp, _Size>::const_reference
226array<_Tp, _Size>::at(size_type __n) const
227{
228 if (__n >= _Size)
229 __throw_out_of_range("array::at");
230 return __elems_[__n];
231}
232
233234template <class _Tp>
234235struct _LIBCPP_TEMPLATE_VIS array<_Tp, 0>
235236{
......@@ -253,44 +254,50 @@ struct _LIBCPP_TEMPLATE_VIS array<_Tp, 0>
253254 struct _ArrayInStructT { _Tp __data_[1]; };
254255 _ALIGNAS_TYPE(_ArrayInStructT) _CharType __elems_[sizeof(_ArrayInStructT)];
255256
257 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
258 value_type* data() _NOEXCEPT {return nullptr;}
259 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
260 const value_type* data() const _NOEXCEPT {return nullptr;}
261
256262 // No explicit construct/copy/destroy for aggregate type
257 _LIBCPP_INLINE_VISIBILITY void fill(const value_type&) {
263 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
264 void fill(const value_type&) {
258265 static_assert(!is_const<_Tp>::value,
259266 "cannot fill zero-sized array of type 'const T'");
260267 }
261268
262 _LIBCPP_INLINE_VISIBILITY
269 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
263270 void swap(array&) _NOEXCEPT {
264271 static_assert(!is_const<_Tp>::value,
265272 "cannot swap zero-sized array of type 'const T'");
266273 }
267274
268275 // iterators:
269 _LIBCPP_INLINE_VISIBILITY
276 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
270277 iterator begin() _NOEXCEPT {return iterator(data());}
271 _LIBCPP_INLINE_VISIBILITY
278 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
272279 const_iterator begin() const _NOEXCEPT {return const_iterator(data());}
273 _LIBCPP_INLINE_VISIBILITY
280 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
274281 iterator end() _NOEXCEPT {return iterator(data());}
275 _LIBCPP_INLINE_VISIBILITY
282 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
276283 const_iterator end() const _NOEXCEPT {return const_iterator(data());}
277284
278 _LIBCPP_INLINE_VISIBILITY
285 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
279286 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
280 _LIBCPP_INLINE_VISIBILITY
287 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
281288 const_reverse_iterator rbegin() const _NOEXCEPT {return const_reverse_iterator(end());}
282 _LIBCPP_INLINE_VISIBILITY
289 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
283290 reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());}
284 _LIBCPP_INLINE_VISIBILITY
291 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
285292 const_reverse_iterator rend() const _NOEXCEPT {return const_reverse_iterator(begin());}
286293
287 _LIBCPP_INLINE_VISIBILITY
294 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
288295 const_iterator cbegin() const _NOEXCEPT {return begin();}
289 _LIBCPP_INLINE_VISIBILITY
296 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
290297 const_iterator cend() const _NOEXCEPT {return end();}
291 _LIBCPP_INLINE_VISIBILITY
298 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
292299 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
293 _LIBCPP_INLINE_VISIBILITY
300 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
294301 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
295302
296303 // capacity:
......@@ -302,7 +309,7 @@ struct _LIBCPP_TEMPLATE_VIS array<_Tp, 0>
302309 _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT {return true;}
303310
304311 // element access:
305 _LIBCPP_INLINE_VISIBILITY
312 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
306313 reference operator[](size_type) _NOEXCEPT {
307314 _LIBCPP_ASSERT(false, "cannot call array<T, 0>::operator[] on a zero-sized array");
308315 _LIBCPP_UNREACHABLE();
......@@ -314,52 +321,47 @@ struct _LIBCPP_TEMPLATE_VIS array<_Tp, 0>
314321 _LIBCPP_UNREACHABLE();
315322 }
316323
317 _LIBCPP_INLINE_VISIBILITY
324 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
318325 reference at(size_type) {
319326 __throw_out_of_range("array<T, 0>::at");
320327 _LIBCPP_UNREACHABLE();
321328 }
322329
323 _LIBCPP_INLINE_VISIBILITY
330 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
324331 const_reference at(size_type) const {
325332 __throw_out_of_range("array<T, 0>::at");
326333 _LIBCPP_UNREACHABLE();
327334 }
328335
329 _LIBCPP_INLINE_VISIBILITY
336 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
330337 reference front() _NOEXCEPT {
331338 _LIBCPP_ASSERT(false, "cannot call array<T, 0>::front() on a zero-sized array");
332339 _LIBCPP_UNREACHABLE();
333340 }
334341
335 _LIBCPP_INLINE_VISIBILITY
342 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
336343 const_reference front() const _NOEXCEPT {
337344 _LIBCPP_ASSERT(false, "cannot call array<T, 0>::front() on a zero-sized array");
338345 _LIBCPP_UNREACHABLE();
339346 }
340347
341 _LIBCPP_INLINE_VISIBILITY
348 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
342349 reference back() _NOEXCEPT {
343350 _LIBCPP_ASSERT(false, "cannot call array<T, 0>::back() on a zero-sized array");
344351 _LIBCPP_UNREACHABLE();
345352 }
346353
347 _LIBCPP_INLINE_VISIBILITY
354 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
348355 const_reference back() const _NOEXCEPT {
349356 _LIBCPP_ASSERT(false, "cannot call array<T, 0>::back() on a zero-sized array");
350357 _LIBCPP_UNREACHABLE();
351358 }
352
353 _LIBCPP_INLINE_VISIBILITY
354 value_type* data() _NOEXCEPT {return reinterpret_cast<value_type*>(__elems_);}
355 _LIBCPP_INLINE_VISIBILITY
356 const value_type* data() const _NOEXCEPT {return reinterpret_cast<const value_type*>(__elems_);}
357359};
358360
359361
360362#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
361363template<class _Tp, class... _Args,
362 class = typename enable_if<(is_same_v<_Tp, _Args> && ...), void>::type
364 class = _EnableIf<__all<_IsSame<_Tp, _Args>::value...>::value>
363365 >
364366array(_Tp, _Args...)
365367 -> array<_Tp, 1 + sizeof...(_Args)>;
......@@ -415,7 +417,7 @@ operator>=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
415417}
416418
417419template <class _Tp, size_t _Size>
418inline _LIBCPP_INLINE_VISIBILITY
420inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
419421typename enable_if
420422<
421423 _Size == 0 ||
......@@ -479,6 +481,47 @@ get(const array<_Tp, _Size>&& __a) _NOEXCEPT
479481
480482#endif // !_LIBCPP_CXX03_LANG
481483
484#if _LIBCPP_STD_VER > 17
485
486template <typename _Tp, size_t _Size, size_t... _Index>
487_LIBCPP_INLINE_VISIBILITY constexpr array<remove_cv_t<_Tp>, _Size>
488__to_array_lvalue_impl(_Tp (&__arr)[_Size], index_sequence<_Index...>) {
489 return {{__arr[_Index]...}};
490}
491
492template <typename _Tp, size_t _Size, size_t... _Index>
493_LIBCPP_INLINE_VISIBILITY constexpr array<remove_cv_t<_Tp>, _Size>
494__to_array_rvalue_impl(_Tp(&&__arr)[_Size], index_sequence<_Index...>) {
495 return {{_VSTD::move(__arr[_Index])...}};
496}
497
498template <typename _Tp, size_t _Size>
499_LIBCPP_INLINE_VISIBILITY constexpr array<remove_cv_t<_Tp>, _Size>
500to_array(_Tp (&__arr)[_Size]) noexcept(is_nothrow_constructible_v<_Tp, _Tp&>) {
501 static_assert(
502 !is_array_v<_Tp>,
503 "[array.creation]/1: to_array does not accept multidimensional arrays.");
504 static_assert(
505 is_constructible_v<_Tp, _Tp&>,
506 "[array.creation]/1: to_array requires copy constructible elements.");
507 return __to_array_lvalue_impl(__arr, make_index_sequence<_Size>());
508}
509
510template <typename _Tp, size_t _Size>
511_LIBCPP_INLINE_VISIBILITY constexpr array<remove_cv_t<_Tp>, _Size>
512to_array(_Tp(&&__arr)[_Size]) noexcept(is_nothrow_move_constructible_v<_Tp>) {
513 static_assert(
514 !is_array_v<_Tp>,
515 "[array.creation]/4: to_array does not accept multidimensional arrays.");
516 static_assert(
517 is_move_constructible_v<_Tp>,
518 "[array.creation]/4: to_array requires move constructible elements.");
519 return __to_array_rvalue_impl(_VSTD::move(__arr),
520 make_index_sequence<_Size>());
521}
522
523#endif // _LIBCPP_STD_VER > 17
524
482525_LIBCPP_END_NAMESPACE_STD
483526
484527#endif // _LIBCPP_ARRAY
lib/libcxx/include/atomic+553-207
......@@ -54,60 +54,30 @@ template <class T> T kill_dependency(T y) noexcept;
5454#define ATOMIC_LLONG_LOCK_FREE unspecified
5555#define ATOMIC_POINTER_LOCK_FREE unspecified
5656
57// flag type and operations
58
59typedef struct atomic_flag
60{
61 bool test_and_set(memory_order m = memory_order_seq_cst) volatile noexcept;
62 bool test_and_set(memory_order m = memory_order_seq_cst) noexcept;
63 void clear(memory_order m = memory_order_seq_cst) volatile noexcept;
64 void clear(memory_order m = memory_order_seq_cst) noexcept;
65 atomic_flag() noexcept = default;
66 atomic_flag(const atomic_flag&) = delete;
67 atomic_flag& operator=(const atomic_flag&) = delete;
68 atomic_flag& operator=(const atomic_flag&) volatile = delete;
69} atomic_flag;
70
71bool
72 atomic_flag_test_and_set(volatile atomic_flag* obj) noexcept;
73
74bool
75 atomic_flag_test_and_set(atomic_flag* obj) noexcept;
76
77bool
78 atomic_flag_test_and_set_explicit(volatile atomic_flag* obj,
79 memory_order m) noexcept;
80
81bool
82 atomic_flag_test_and_set_explicit(atomic_flag* obj, memory_order m) noexcept;
83
84void
85 atomic_flag_clear(volatile atomic_flag* obj) noexcept;
86
87void
88 atomic_flag_clear(atomic_flag* obj) noexcept;
89
90void
91 atomic_flag_clear_explicit(volatile atomic_flag* obj, memory_order m) noexcept;
92
93void
94 atomic_flag_clear_explicit(atomic_flag* obj, memory_order m) noexcept;
95
96#define ATOMIC_FLAG_INIT see below
97#define ATOMIC_VAR_INIT(value) see below
98
9957template <class T>
10058struct atomic
10159{
60 using value_type = T;
61
10262 static constexpr bool is_always_lock_free;
10363 bool is_lock_free() const volatile noexcept;
10464 bool is_lock_free() const noexcept;
105 void store(T desr, memory_order m = memory_order_seq_cst) volatile noexcept;
106 void store(T desr, memory_order m = memory_order_seq_cst) noexcept;
65
66 atomic() noexcept = default;
67 constexpr atomic(T desr) noexcept;
68 atomic(const atomic&) = delete;
69 atomic& operator=(const atomic&) = delete;
70 atomic& operator=(const atomic&) volatile = delete;
71
10772 T load(memory_order m = memory_order_seq_cst) const volatile noexcept;
10873 T load(memory_order m = memory_order_seq_cst) const noexcept;
10974 operator T() const volatile noexcept;
11075 operator T() const noexcept;
76 void store(T desr, memory_order m = memory_order_seq_cst) volatile noexcept;
77 void store(T desr, memory_order m = memory_order_seq_cst) noexcept;
78 T operator=(T) volatile noexcept;
79 T operator=(T) noexcept;
80
11181 T exchange(T desr, memory_order m = memory_order_seq_cst) volatile noexcept;
11282 T exchange(T desr, memory_order m = memory_order_seq_cst) noexcept;
11383 bool compare_exchange_weak(T& expc, T desr,
......@@ -126,27 +96,38 @@ struct atomic
12696 bool compare_exchange_strong(T& expc, T desr,
12797 memory_order m = memory_order_seq_cst) noexcept;
12898
129 atomic() noexcept = default;
130 constexpr atomic(T desr) noexcept;
131 atomic(const atomic&) = delete;
132 atomic& operator=(const atomic&) = delete;
133 atomic& operator=(const atomic&) volatile = delete;
134 T operator=(T) volatile noexcept;
135 T operator=(T) noexcept;
99 void wait(T, memory_order = memory_order::seq_cst) const volatile noexcept;
100 void wait(T, memory_order = memory_order::seq_cst) const noexcept;
101 void notify_one() volatile noexcept;
102 void notify_one() noexcept;
103 void notify_all() volatile noexcept;
104 void notify_all() noexcept;
136105};
137106
138107template <>
139108struct atomic<integral>
140109{
110 using value_type = integral;
111
141112 static constexpr bool is_always_lock_free;
142113 bool is_lock_free() const volatile noexcept;
143114 bool is_lock_free() const noexcept;
144 void store(integral desr, memory_order m = memory_order_seq_cst) volatile noexcept;
145 void store(integral desr, memory_order m = memory_order_seq_cst) noexcept;
115
116 atomic() noexcept = default;
117 constexpr atomic(integral desr) noexcept;
118 atomic(const atomic&) = delete;
119 atomic& operator=(const atomic&) = delete;
120 atomic& operator=(const atomic&) volatile = delete;
121
146122 integral load(memory_order m = memory_order_seq_cst) const volatile noexcept;
147123 integral load(memory_order m = memory_order_seq_cst) const noexcept;
148124 operator integral() const volatile noexcept;
149125 operator integral() const noexcept;
126 void store(integral desr, memory_order m = memory_order_seq_cst) volatile noexcept;
127 void store(integral desr, memory_order m = memory_order_seq_cst) noexcept;
128 integral operator=(integral desr) volatile noexcept;
129 integral operator=(integral desr) noexcept;
130
150131 integral exchange(integral desr,
151132 memory_order m = memory_order_seq_cst) volatile noexcept;
152133 integral exchange(integral desr, memory_order m = memory_order_seq_cst) noexcept;
......@@ -167,30 +148,17 @@ struct atomic<integral>
167148 bool compare_exchange_strong(integral& expc, integral desr,
168149 memory_order m = memory_order_seq_cst) noexcept;
169150
170 integral
171 fetch_add(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
151 integral fetch_add(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
172152 integral fetch_add(integral op, memory_order m = memory_order_seq_cst) noexcept;
173 integral
174 fetch_sub(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
153 integral fetch_sub(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
175154 integral fetch_sub(integral op, memory_order m = memory_order_seq_cst) noexcept;
176 integral
177 fetch_and(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
155 integral fetch_and(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
178156 integral fetch_and(integral op, memory_order m = memory_order_seq_cst) noexcept;
179 integral
180 fetch_or(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
157 integral fetch_or(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
181158 integral fetch_or(integral op, memory_order m = memory_order_seq_cst) noexcept;
182 integral
183 fetch_xor(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
159 integral fetch_xor(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
184160 integral fetch_xor(integral op, memory_order m = memory_order_seq_cst) noexcept;
185161
186 atomic() noexcept = default;
187 constexpr atomic(integral desr) noexcept;
188 atomic(const atomic&) = delete;
189 atomic& operator=(const atomic&) = delete;
190 atomic& operator=(const atomic&) volatile = delete;
191 integral operator=(integral desr) volatile noexcept;
192 integral operator=(integral desr) noexcept;
193
194162 integral operator++(int) volatile noexcept;
195163 integral operator++(int) noexcept;
196164 integral operator--(int) volatile noexcept;
......@@ -209,20 +177,39 @@ struct atomic<integral>
209177 integral operator|=(integral op) noexcept;
210178 integral operator^=(integral op) volatile noexcept;
211179 integral operator^=(integral op) noexcept;
180
181 void wait(integral, memory_order = memory_order::seq_cst) const volatile noexcept;
182 void wait(integral, memory_order = memory_order::seq_cst) const noexcept;
183 void notify_one() volatile noexcept;
184 void notify_one() noexcept;
185 void notify_all() volatile noexcept;
186 void notify_all() noexcept;
212187};
213188
214189template <class T>
215190struct atomic<T*>
216191{
192 using value_type = T*;
193
217194 static constexpr bool is_always_lock_free;
218195 bool is_lock_free() const volatile noexcept;
219196 bool is_lock_free() const noexcept;
220 void store(T* desr, memory_order m = memory_order_seq_cst) volatile noexcept;
221 void store(T* desr, memory_order m = memory_order_seq_cst) noexcept;
197
198 atomic() noexcept = default;
199 constexpr atomic(T* desr) noexcept;
200 atomic(const atomic&) = delete;
201 atomic& operator=(const atomic&) = delete;
202 atomic& operator=(const atomic&) volatile = delete;
203
222204 T* load(memory_order m = memory_order_seq_cst) const volatile noexcept;
223205 T* load(memory_order m = memory_order_seq_cst) const noexcept;
224206 operator T*() const volatile noexcept;
225207 operator T*() const noexcept;
208 void store(T* desr, memory_order m = memory_order_seq_cst) volatile noexcept;
209 void store(T* desr, memory_order m = memory_order_seq_cst) noexcept;
210 T* operator=(T*) volatile noexcept;
211 T* operator=(T*) noexcept;
212
226213 T* exchange(T* desr, memory_order m = memory_order_seq_cst) volatile noexcept;
227214 T* exchange(T* desr, memory_order m = memory_order_seq_cst) noexcept;
228215 bool compare_exchange_weak(T*& expc, T* desr,
......@@ -246,14 +233,6 @@ struct atomic<T*>
246233 T* fetch_sub(ptrdiff_t op, memory_order m = memory_order_seq_cst) volatile noexcept;
247234 T* fetch_sub(ptrdiff_t op, memory_order m = memory_order_seq_cst) noexcept;
248235
249 atomic() noexcept = default;
250 constexpr atomic(T* desr) noexcept;
251 atomic(const atomic&) = delete;
252 atomic& operator=(const atomic&) = delete;
253 atomic& operator=(const atomic&) volatile = delete;
254
255 T* operator=(T*) volatile noexcept;
256 T* operator=(T*) noexcept;
257236 T* operator++(int) volatile noexcept;
258237 T* operator++(int) noexcept;
259238 T* operator--(int) volatile noexcept;
......@@ -266,224 +245,206 @@ struct atomic<T*>
266245 T* operator+=(ptrdiff_t op) noexcept;
267246 T* operator-=(ptrdiff_t op) volatile noexcept;
268247 T* operator-=(ptrdiff_t op) noexcept;
248
249 void wait(T*, memory_order = memory_order::seq_cst) const volatile noexcept;
250 void wait(T*, memory_order = memory_order::seq_cst) const noexcept;
251 void notify_one() volatile noexcept;
252 void notify_one() noexcept;
253 void notify_all() volatile noexcept;
254 void notify_all() noexcept;
269255};
270256
271257
272258template <class T>
273 bool
274 atomic_is_lock_free(const volatile atomic<T>* obj) noexcept;
259 bool atomic_is_lock_free(const volatile atomic<T>* obj) noexcept;
260
261template <class T>
262 bool atomic_is_lock_free(const atomic<T>* obj) noexcept;
263
264template <class T>
265 void atomic_store(volatile atomic<T>* obj, T desr) noexcept;
266
267template <class T>
268 void atomic_store(atomic<T>* obj, T desr) noexcept;
269
270template <class T>
271 void atomic_store_explicit(volatile atomic<T>* obj, T desr, memory_order m) noexcept;
272
273template <class T>
274 void atomic_store_explicit(atomic<T>* obj, T desr, memory_order m) noexcept;
275
276template <class T>
277 T atomic_load(const volatile atomic<T>* obj) noexcept;
275278
276279template <class T>
277 bool
278 atomic_is_lock_free(const atomic<T>* obj) noexcept;
280 T atomic_load(const atomic<T>* obj) noexcept;
279281
280282template <class T>
281 void
282 atomic_init(volatile atomic<T>* obj, T desr) noexcept;
283 T atomic_load_explicit(const volatile atomic<T>* obj, memory_order m) noexcept;
283284
284285template <class T>
285 void
286 atomic_init(atomic<T>* obj, T desr) noexcept;
286 T atomic_load_explicit(const atomic<T>* obj, memory_order m) noexcept;
287287
288288template <class T>
289 void
290 atomic_store(volatile atomic<T>* obj, T desr) noexcept;
289 T atomic_exchange(volatile atomic<T>* obj, T desr) noexcept;
291290
292291template <class T>
293 void
294 atomic_store(atomic<T>* obj, T desr) noexcept;
292 T atomic_exchange(atomic<T>* obj, T desr) noexcept;
295293
296294template <class T>
297 void
298 atomic_store_explicit(volatile atomic<T>* obj, T desr, memory_order m) noexcept;
295 T atomic_exchange_explicit(volatile atomic<T>* obj, T desr, memory_order m) noexcept;
299296
300297template <class T>
301 void
302 atomic_store_explicit(atomic<T>* obj, T desr, memory_order m) noexcept;
298 T atomic_exchange_explicit(atomic<T>* obj, T desr, memory_order m) noexcept;
303299
304300template <class T>
305 T
306 atomic_load(const volatile atomic<T>* obj) noexcept;
301 bool atomic_compare_exchange_weak(volatile atomic<T>* obj, T* expc, T desr) noexcept;
307302
308303template <class T>
309 T
310 atomic_load(const atomic<T>* obj) noexcept;
304 bool atomic_compare_exchange_weak(atomic<T>* obj, T* expc, T desr) noexcept;
311305
312306template <class T>
313 T
314 atomic_load_explicit(const volatile atomic<T>* obj, memory_order m) noexcept;
307 bool atomic_compare_exchange_strong(volatile atomic<T>* obj, T* expc, T desr) noexcept;
315308
316309template <class T>
317 T
318 atomic_load_explicit(const atomic<T>* obj, memory_order m) noexcept;
310 bool atomic_compare_exchange_strong(atomic<T>* obj, T* expc, T desr) noexcept;
319311
320312template <class T>
321 T
322 atomic_exchange(volatile atomic<T>* obj, T desr) noexcept;
313 bool atomic_compare_exchange_weak_explicit(volatile atomic<T>* obj, T* expc,
314 T desr,
315 memory_order s, memory_order f) noexcept;
323316
324317template <class T>
325 T
326 atomic_exchange(atomic<T>* obj, T desr) noexcept;
318 bool atomic_compare_exchange_weak_explicit(atomic<T>* obj, T* expc, T desr,
319 memory_order s, memory_order f) noexcept;
327320
328321template <class T>
329 T
330 atomic_exchange_explicit(volatile atomic<T>* obj, T desr, memory_order m) noexcept;
322 bool atomic_compare_exchange_strong_explicit(volatile atomic<T>* obj,
323 T* expc, T desr,
324 memory_order s, memory_order f) noexcept;
331325
332326template <class T>
333 T
334 atomic_exchange_explicit(atomic<T>* obj, T desr, memory_order m) noexcept;
327 bool atomic_compare_exchange_strong_explicit(atomic<T>* obj, T* expc,
328 T desr,
329 memory_order s, memory_order f) noexcept;
335330
336331template <class T>
337 bool
338 atomic_compare_exchange_weak(volatile atomic<T>* obj, T* expc, T desr) noexcept;
332 void atomic_wait(const volatile atomic<T>* obj, T old) noexcept;
339333
340334template <class T>
341 bool
342 atomic_compare_exchange_weak(atomic<T>* obj, T* expc, T desr) noexcept;
335 void atomic_wait(const atomic<T>* obj, T old) noexcept;
343336
344337template <class T>
345 bool
346 atomic_compare_exchange_strong(volatile atomic<T>* obj, T* expc, T desr) noexcept;
338 void atomic_wait_explicit(const volatile atomic<T>* obj, T old, memory_order m) noexcept;
347339
348340template <class T>
349 bool
350 atomic_compare_exchange_strong(atomic<T>* obj, T* expc, T desr) noexcept;
341 void atomic_wait_explicit(const atomic<T>* obj, T old, memory_order m) noexcept;
351342
352343template <class T>
353 bool
354 atomic_compare_exchange_weak_explicit(volatile atomic<T>* obj, T* expc,
355 T desr,
356 memory_order s, memory_order f) noexcept;
344 void atomic_one(volatile atomic<T>* obj) noexcept;
357345
358346template <class T>
359 bool
360 atomic_compare_exchange_weak_explicit(atomic<T>* obj, T* expc, T desr,
361 memory_order s, memory_order f) noexcept;
347 void atomic_one(atomic<T>* obj) noexcept;
362348
363349template <class T>
364 bool
365 atomic_compare_exchange_strong_explicit(volatile atomic<T>* obj,
366 T* expc, T desr,
367 memory_order s, memory_order f) noexcept;
350 void atomic_all(volatile atomic<T>* obj) noexcept;
368351
369352template <class T>
370 bool
371 atomic_compare_exchange_strong_explicit(atomic<T>* obj, T* expc,
372 T desr,
373 memory_order s, memory_order f) noexcept;
353 void atomic_all(atomic<T>* obj) noexcept;
374354
375355template <class Integral>
376 Integral
377 atomic_fetch_add(volatile atomic<Integral>* obj, Integral op) noexcept;
356 Integral atomic_fetch_add(volatile atomic<Integral>* obj, Integral op) noexcept;
378357
379358template <class Integral>
380 Integral
381 atomic_fetch_add(atomic<Integral>* obj, Integral op) noexcept;
359 Integral atomic_fetch_add(atomic<Integral>* obj, Integral op) noexcept;
382360
383361template <class Integral>
384 Integral
385 atomic_fetch_add_explicit(volatile atomic<Integral>* obj, Integral op,
362 Integral atomic_fetch_add_explicit(volatile atomic<Integral>* obj, Integral op,
386363 memory_order m) noexcept;
387364template <class Integral>
388 Integral
389 atomic_fetch_add_explicit(atomic<Integral>* obj, Integral op,
365 Integral atomic_fetch_add_explicit(atomic<Integral>* obj, Integral op,
390366 memory_order m) noexcept;
391367template <class Integral>
392 Integral
393 atomic_fetch_sub(volatile atomic<Integral>* obj, Integral op) noexcept;
368 Integral atomic_fetch_sub(volatile atomic<Integral>* obj, Integral op) noexcept;
394369
395370template <class Integral>
396 Integral
397 atomic_fetch_sub(atomic<Integral>* obj, Integral op) noexcept;
371 Integral atomic_fetch_sub(atomic<Integral>* obj, Integral op) noexcept;
398372
399373template <class Integral>
400 Integral
401 atomic_fetch_sub_explicit(volatile atomic<Integral>* obj, Integral op,
402 memory_order m) noexcept;
374 Integral atomic_fetch_sub_explicit(volatile atomic<Integral>* obj, Integral op,
375 memory_order m) noexcept;
376
403377template <class Integral>
404 Integral
405 atomic_fetch_sub_explicit(atomic<Integral>* obj, Integral op,
406 memory_order m) noexcept;
378 Integral atomic_fetch_sub_explicit(atomic<Integral>* obj, Integral op,
379 memory_order m) noexcept;
380
407381template <class Integral>
408 Integral
409 atomic_fetch_and(volatile atomic<Integral>* obj, Integral op) noexcept;
382 Integral atomic_fetch_and(volatile atomic<Integral>* obj, Integral op) noexcept;
410383
411384template <class Integral>
412 Integral
413 atomic_fetch_and(atomic<Integral>* obj, Integral op) noexcept;
385 Integral atomic_fetch_and(atomic<Integral>* obj, Integral op) noexcept;
414386
415387template <class Integral>
416 Integral
417 atomic_fetch_and_explicit(volatile atomic<Integral>* obj, Integral op,
418 memory_order m) noexcept;
388 Integral atomic_fetch_and_explicit(volatile atomic<Integral>* obj, Integral op,
389 memory_order m) noexcept;
390
419391template <class Integral>
420 Integral
421 atomic_fetch_and_explicit(atomic<Integral>* obj, Integral op,
422 memory_order m) noexcept;
392 Integral atomic_fetch_and_explicit(atomic<Integral>* obj, Integral op,
393 memory_order m) noexcept;
394
423395template <class Integral>
424 Integral
425 atomic_fetch_or(volatile atomic<Integral>* obj, Integral op) noexcept;
396 Integral atomic_fetch_or(volatile atomic<Integral>* obj, Integral op) noexcept;
426397
427398template <class Integral>
428 Integral
429 atomic_fetch_or(atomic<Integral>* obj, Integral op) noexcept;
399 Integral atomic_fetch_or(atomic<Integral>* obj, Integral op) noexcept;
430400
431401template <class Integral>
432 Integral
433 atomic_fetch_or_explicit(volatile atomic<Integral>* obj, Integral op,
402 Integral atomic_fetch_or_explicit(volatile atomic<Integral>* obj, Integral op,
434403 memory_order m) noexcept;
404
435405template <class Integral>
436 Integral
437 atomic_fetch_or_explicit(atomic<Integral>* obj, Integral op,
406 Integral atomic_fetch_or_explicit(atomic<Integral>* obj, Integral op,
438407 memory_order m) noexcept;
408
439409template <class Integral>
440 Integral
441 atomic_fetch_xor(volatile atomic<Integral>* obj, Integral op) noexcept;
410 Integral atomic_fetch_xor(volatile atomic<Integral>* obj, Integral op) noexcept;
442411
443412template <class Integral>
444 Integral
445 atomic_fetch_xor(atomic<Integral>* obj, Integral op) noexcept;
413 Integral atomic_fetch_xor(atomic<Integral>* obj, Integral op) noexcept;
446414
447415template <class Integral>
448 Integral
449 atomic_fetch_xor_explicit(volatile atomic<Integral>* obj, Integral op,
450 memory_order m) noexcept;
416 Integral atomic_fetch_xor_explicit(volatile atomic<Integral>* obj, Integral op,
417 memory_order m) noexcept;
418
451419template <class Integral>
452 Integral
453 atomic_fetch_xor_explicit(atomic<Integral>* obj, Integral op,
454 memory_order m) noexcept;
420 Integral atomic_fetch_xor_explicit(atomic<Integral>* obj, Integral op,
421 memory_order m) noexcept;
455422
456423template <class T>
457 T*
458 atomic_fetch_add(volatile atomic<T*>* obj, ptrdiff_t op) noexcept;
424 T* atomic_fetch_add(volatile atomic<T*>* obj, ptrdiff_t op) noexcept;
459425
460426template <class T>
461 T*
462 atomic_fetch_add(atomic<T*>* obj, ptrdiff_t op) noexcept;
427 T* atomic_fetch_add(atomic<T*>* obj, ptrdiff_t op) noexcept;
463428
464429template <class T>
465 T*
466 atomic_fetch_add_explicit(volatile atomic<T*>* obj, ptrdiff_t op,
467 memory_order m) noexcept;
430 T* atomic_fetch_add_explicit(volatile atomic<T*>* obj, ptrdiff_t op,
431 memory_order m) noexcept;
432
468433template <class T>
469 T*
470 atomic_fetch_add_explicit(atomic<T*>* obj, ptrdiff_t op, memory_order m) noexcept;
434 T* atomic_fetch_add_explicit(atomic<T*>* obj, ptrdiff_t op, memory_order m) noexcept;
471435
472436template <class T>
473 T*
474 atomic_fetch_sub(volatile atomic<T*>* obj, ptrdiff_t op) noexcept;
437 T* atomic_fetch_sub(volatile atomic<T*>* obj, ptrdiff_t op) noexcept;
475438
476439template <class T>
477 T*
478 atomic_fetch_sub(atomic<T*>* obj, ptrdiff_t op) noexcept;
440 T* atomic_fetch_sub(atomic<T*>* obj, ptrdiff_t op) noexcept;
479441
480442template <class T>
481 T*
482 atomic_fetch_sub_explicit(volatile atomic<T*>* obj, ptrdiff_t op,
483 memory_order m) noexcept;
443 T* atomic_fetch_sub_explicit(volatile atomic<T*>* obj, ptrdiff_t op,
444 memory_order m) noexcept;
445
484446template <class T>
485 T*
486 atomic_fetch_sub_explicit(atomic<T*>* obj, ptrdiff_t op, memory_order m) noexcept;
447 T* atomic_fetch_sub_explicit(atomic<T*>* obj, ptrdiff_t op, memory_order m) noexcept;
487448
488449// Atomics for standard typedef types
489450
......@@ -516,7 +477,7 @@ typedef atomic<int_fast8_t> atomic_int_fast8_t;
516477typedef atomic<uint_fast8_t> atomic_uint_fast8_t;
517478typedef atomic<int_fast16_t> atomic_int_fast16_t;
518479typedef atomic<uint_fast16_t> atomic_uint_fast16_t;
519typedef atomic<int_fast32_t> atomic_int_fast32_t;
480typedef atomic<int_fast32_t> atomic_int_fast32_t;
520481typedef atomic<uint_fast32_t> atomic_uint_fast32_t;
521482typedef atomic<int_fast64_t> atomic_int_fast64_t;
522483typedef atomic<uint_fast64_t> atomic_uint_fast64_t;
......@@ -537,18 +498,80 @@ typedef atomic<ptrdiff_t> atomic_ptrdiff_t;
537498typedef atomic<intmax_t> atomic_intmax_t;
538499typedef atomic<uintmax_t> atomic_uintmax_t;
539500
501// flag type and operations
502
503typedef struct atomic_flag
504{
505 atomic_flag() noexcept = default;
506 atomic_flag(const atomic_flag&) = delete;
507 atomic_flag& operator=(const atomic_flag&) = delete;
508 atomic_flag& operator=(const atomic_flag&) volatile = delete;
509
510 bool test(memory_order m = memory_order_seq_cst) volatile noexcept;
511 bool test(memory_order m = memory_order_seq_cst) noexcept;
512 bool test_and_set(memory_order m = memory_order_seq_cst) volatile noexcept;
513 bool test_and_set(memory_order m = memory_order_seq_cst) noexcept;
514 void clear(memory_order m = memory_order_seq_cst) volatile noexcept;
515 void clear(memory_order m = memory_order_seq_cst) noexcept;
516
517 void wait(bool, memory_order = memory_order::seq_cst) const volatile noexcept;
518 void wait(bool, memory_order = memory_order::seq_cst) const noexcept;
519 void notify_one() volatile noexcept;
520 void notify_one() noexcept;
521 void notify_all() volatile noexcept;
522 void notify_all() noexcept;
523} atomic_flag;
524
525bool atomic_flag_test(volatile atomic_flag* obj) noexcept;
526bool atomic_flag_test(atomic_flag* obj) noexcept;
527bool atomic_flag_test_explicit(volatile atomic_flag* obj,
528 memory_order m) noexcept;
529bool atomic_flag_test_explicit(atomic_flag* obj, memory_order m) noexcept;
530bool atomic_flag_test_and_set(volatile atomic_flag* obj) noexcept;
531bool atomic_flag_test_and_set(atomic_flag* obj) noexcept;
532bool atomic_flag_test_and_set_explicit(volatile atomic_flag* obj,
533 memory_order m) noexcept;
534bool atomic_flag_test_and_set_explicit(atomic_flag* obj, memory_order m) noexcept;
535void atomic_flag_clear(volatile atomic_flag* obj) noexcept;
536void atomic_flag_clear(atomic_flag* obj) noexcept;
537void atomic_flag_clear_explicit(volatile atomic_flag* obj, memory_order m) noexcept;
538void atomic_flag_clear_explicit(atomic_flag* obj, memory_order m) noexcept;
539
540void atomic_wait(const volatile atomic_flag* obj, T old) noexcept;
541void atomic_wait(const atomic_flag* obj, T old) noexcept;
542void atomic_wait_explicit(const volatile atomic_flag* obj, T old, memory_order m) noexcept;
543void atomic_wait_explicit(const atomic_flag* obj, T old, memory_order m) noexcept;
544void atomic_one(volatile atomic_flag* obj) noexcept;
545void atomic_one(atomic_flag* obj) noexcept;
546void atomic_all(volatile atomic_flag* obj) noexcept;
547void atomic_all(atomic_flag* obj) noexcept;
548
540549// fences
541550
542551void atomic_thread_fence(memory_order m) noexcept;
543552void atomic_signal_fence(memory_order m) noexcept;
544553
554// deprecated
555
556template <class T>
557 void atomic_init(volatile atomic<T>* obj, typename atomic<T>::value_type desr) noexcept;
558
559template <class T>
560 void atomic_init(atomic<T>* obj, typename atomic<T>::value_type desr) noexcept;
561
562#define ATOMIC_VAR_INIT(value) see below
563
564#define ATOMIC_FLAG_INIT see below
565
545566} // std
546567
547568*/
548569
549570#include <__config>
571#include <__threading_support>
550572#include <cstddef>
551573#include <cstdint>
574#include <cstring>
552575#include <type_traits>
553576#include <version>
554577
......@@ -629,6 +652,11 @@ typedef enum memory_order {
629652
630653#endif // _LIBCPP_STD_VER > 17
631654
655template <typename _Tp> _LIBCPP_INLINE_VISIBILITY
656bool __cxx_nonatomic_compare_equal(_Tp const& __lhs, _Tp const& __rhs) {
657 return memcmp(&__lhs, &__rhs, sizeof(_Tp)) == 0;
658}
659
632660static_assert((is_same<underlying_type<memory_order>::type, __memory_order_underlying_t>::value),
633661 "unexpected underlying type for std::memory_order");
634662
......@@ -1218,9 +1246,9 @@ _LIBCPP_INLINE_VISIBILITY
12181246bool __cxx_atomic_compare_exchange_strong(volatile __cxx_atomic_lock_impl<_Tp>* __a,
12191247 _Tp* __expected, _Tp __value, memory_order, memory_order) {
12201248 __a->__lock();
1221 _Tp temp;
1222 __cxx_atomic_assign_volatile(temp, __a->__a_value);
1223 bool __ret = temp == *__expected;
1249 _Tp __temp;
1250 __cxx_atomic_assign_volatile(__temp, __a->__a_value);
1251 bool __ret = __temp == *__expected;
12241252 if(__ret)
12251253 __cxx_atomic_assign_volatile(__a->__a_value, __value);
12261254 else
......@@ -1247,9 +1275,9 @@ _LIBCPP_INLINE_VISIBILITY
12471275bool __cxx_atomic_compare_exchange_weak(volatile __cxx_atomic_lock_impl<_Tp>* __a,
12481276 _Tp* __expected, _Tp __value, memory_order, memory_order) {
12491277 __a->__lock();
1250 _Tp temp;
1251 __cxx_atomic_assign_volatile(temp, __a->__a_value);
1252 bool __ret = temp == *__expected;
1278 _Tp __temp;
1279 __cxx_atomic_assign_volatile(__temp, __a->__a_value);
1280 bool __ret = __temp == *__expected;
12531281 if(__ret)
12541282 __cxx_atomic_assign_volatile(__a->__a_value, __value);
12551283 else
......@@ -1452,6 +1480,93 @@ struct __cxx_atomic_impl : public _Base {
14521480 : _Base(value) {}
14531481};
14541482
1483#ifdef __linux__
1484 using __cxx_contention_t = int32_t;
1485#else
1486 using __cxx_contention_t = int64_t;
1487#endif //__linux__
1488
1489#if _LIBCPP_STD_VER >= 11
1490
1491using __cxx_atomic_contention_t = __cxx_atomic_impl<__cxx_contention_t>;
1492
1493#ifndef _LIBCPP_HAS_NO_PLATFORM_WAIT
1494
1495_LIBCPP_AVAILABILITY_SYNC _LIBCPP_EXPORTED_FROM_ABI void __cxx_atomic_notify_one(void const volatile*);
1496_LIBCPP_AVAILABILITY_SYNC _LIBCPP_EXPORTED_FROM_ABI void __cxx_atomic_notify_all(void const volatile*);
1497_LIBCPP_AVAILABILITY_SYNC _LIBCPP_EXPORTED_FROM_ABI __cxx_contention_t __libcpp_atomic_monitor(void const volatile*);
1498_LIBCPP_AVAILABILITY_SYNC _LIBCPP_EXPORTED_FROM_ABI void __libcpp_atomic_wait(void const volatile*, __cxx_contention_t);
1499
1500_LIBCPP_AVAILABILITY_SYNC _LIBCPP_EXPORTED_FROM_ABI void __cxx_atomic_notify_one(__cxx_atomic_contention_t const volatile*);
1501_LIBCPP_AVAILABILITY_SYNC _LIBCPP_EXPORTED_FROM_ABI void __cxx_atomic_notify_all(__cxx_atomic_contention_t const volatile*);
1502_LIBCPP_AVAILABILITY_SYNC _LIBCPP_EXPORTED_FROM_ABI __cxx_contention_t __libcpp_atomic_monitor(__cxx_atomic_contention_t const volatile*);
1503_LIBCPP_AVAILABILITY_SYNC _LIBCPP_EXPORTED_FROM_ABI void __libcpp_atomic_wait(__cxx_atomic_contention_t const volatile*, __cxx_contention_t);
1504
1505template <class _Atp, class _Fn>
1506struct __libcpp_atomic_wait_backoff_impl {
1507 _Atp* __a;
1508 _Fn __test_fn;
1509 _LIBCPP_AVAILABILITY_SYNC
1510 _LIBCPP_INLINE_VISIBILITY bool operator()(chrono::nanoseconds __elapsed) const
1511 {
1512 if(__elapsed > chrono::microseconds(64))
1513 {
1514 auto const __monitor = __libcpp_atomic_monitor(__a);
1515 if(__test_fn())
1516 return true;
1517 __libcpp_atomic_wait(__a, __monitor);
1518 }
1519 else if(__elapsed > chrono::microseconds(4))
1520 __libcpp_thread_yield();
1521 else
1522 ; // poll
1523 return false;
1524 }
1525};
1526
1527template <class _Atp, class _Fn>
1528_LIBCPP_AVAILABILITY_SYNC
1529_LIBCPP_INLINE_VISIBILITY bool __cxx_atomic_wait(_Atp* __a, _Fn && __test_fn)
1530{
1531 __libcpp_atomic_wait_backoff_impl<_Atp, typename decay<_Fn>::type> __backoff_fn = {__a, __test_fn};
1532 return __libcpp_thread_poll_with_backoff(__test_fn, __backoff_fn);
1533}
1534
1535#else // _LIBCPP_HAS_NO_PLATFORM_WAIT
1536
1537template <class _Tp>
1538_LIBCPP_INLINE_VISIBILITY void __cxx_atomic_notify_all(__cxx_atomic_impl<_Tp> const volatile*) { }
1539template <class _Tp>
1540_LIBCPP_INLINE_VISIBILITY void __cxx_atomic_notify_one(__cxx_atomic_impl<_Tp> const volatile*) { }
1541template <class _Atp, class _Fn>
1542_LIBCPP_INLINE_VISIBILITY bool __cxx_atomic_wait(_Atp*, _Fn && __test_fn)
1543{
1544 return __libcpp_thread_poll_with_backoff(__test_fn, __libcpp_timed_backoff_policy());
1545}
1546
1547#endif // _LIBCPP_HAS_NO_PLATFORM_WAIT
1548
1549template <class _Atp, class _Tp>
1550struct __cxx_atomic_wait_test_fn_impl {
1551 _Atp* __a;
1552 _Tp __val;
1553 memory_order __order;
1554 _LIBCPP_INLINE_VISIBILITY bool operator()() const
1555 {
1556 return !__cxx_nonatomic_compare_equal(__cxx_atomic_load(__a, __order), __val);
1557 }
1558};
1559
1560template <class _Atp, class _Tp>
1561_LIBCPP_AVAILABILITY_SYNC
1562_LIBCPP_INLINE_VISIBILITY bool __cxx_atomic_wait(_Atp* __a, _Tp const __val, memory_order __order)
1563{
1564 __cxx_atomic_wait_test_fn_impl<_Atp, _Tp> __test_fn = {__a, __val, __order};
1565 return __cxx_atomic_wait(__a, __test_fn);
1566}
1567
1568#endif //_LIBCPP_STD_VER >= 11
1569
14551570// general atomic<T>
14561571
14571572template <class _Tp, bool = is_integral<_Tp>::value && !is_same<_Tp, bool>::value>
......@@ -1532,6 +1647,19 @@ struct __atomic_base // false
15321647 memory_order __m = memory_order_seq_cst) _NOEXCEPT
15331648 {return __cxx_atomic_compare_exchange_strong(&__a_, &__e, __d, __m, __m);}
15341649
1650 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY void wait(_Tp __v, memory_order __m = memory_order_seq_cst) const volatile _NOEXCEPT
1651 {__cxx_atomic_wait(&__a_, __v, __m);}
1652 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY void wait(_Tp __v, memory_order __m = memory_order_seq_cst) const _NOEXCEPT
1653 {__cxx_atomic_wait(&__a_, __v, __m);}
1654 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY void notify_one() volatile _NOEXCEPT
1655 {__cxx_atomic_notify_one(&__a_);}
1656 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY void notify_one() _NOEXCEPT
1657 {__cxx_atomic_notify_one(&__a_);}
1658 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY void notify_all() volatile _NOEXCEPT
1659 {__cxx_atomic_notify_all(&__a_);}
1660 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY void notify_all() _NOEXCEPT
1661 {__cxx_atomic_notify_all(&__a_);}
1662
15351663 _LIBCPP_INLINE_VISIBILITY
15361664 __atomic_base() _NOEXCEPT _LIBCPP_DEFAULT
15371665
......@@ -1544,8 +1672,11 @@ struct __atomic_base // false
15441672 __atomic_base& operator=(const __atomic_base&) volatile = delete;
15451673#else
15461674private:
1675 _LIBCPP_INLINE_VISIBILITY
15471676 __atomic_base(const __atomic_base&);
1677 _LIBCPP_INLINE_VISIBILITY
15481678 __atomic_base& operator=(const __atomic_base&);
1679 _LIBCPP_INLINE_VISIBILITY
15491680 __atomic_base& operator=(const __atomic_base&) volatile;
15501681#endif
15511682};
......@@ -1643,6 +1774,7 @@ struct atomic
16431774 : public __atomic_base<_Tp>
16441775{
16451776 typedef __atomic_base<_Tp> __base;
1777 typedef _Tp value_type;
16461778 _LIBCPP_INLINE_VISIBILITY
16471779 atomic() _NOEXCEPT _LIBCPP_DEFAULT
16481780 _LIBCPP_INLINE_VISIBILITY
......@@ -1663,6 +1795,7 @@ struct atomic<_Tp*>
16631795 : public __atomic_base<_Tp*>
16641796{
16651797 typedef __atomic_base<_Tp*> __base;
1798 typedef _Tp* value_type;
16661799 _LIBCPP_INLINE_VISIBILITY
16671800 atomic() _NOEXCEPT _LIBCPP_DEFAULT
16681801 _LIBCPP_INLINE_VISIBILITY
......@@ -1947,6 +2080,76 @@ atomic_compare_exchange_strong_explicit(atomic<_Tp>* __o, _Tp* __e,
19472080 return __o->compare_exchange_strong(*__e, __d, __s, __f);
19482081}
19492082
2083// atomic_wait
2084
2085template <class _Tp>
2086_LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
2087void atomic_wait(const volatile atomic<_Tp>* __o,
2088 typename atomic<_Tp>::value_type __v) _NOEXCEPT
2089{
2090 return __o->wait(__v);
2091}
2092
2093template <class _Tp>
2094_LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
2095void atomic_wait(const atomic<_Tp>* __o,
2096 typename atomic<_Tp>::value_type __v) _NOEXCEPT
2097{
2098 return __o->wait(__v);
2099}
2100
2101// atomic_wait_explicit
2102
2103template <class _Tp>
2104_LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
2105void atomic_wait_explicit(const volatile atomic<_Tp>* __o,
2106 typename atomic<_Tp>::value_type __v,
2107 memory_order __m) _NOEXCEPT
2108 _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m)
2109{
2110 return __o->wait(__v, __m);
2111}
2112
2113template <class _Tp>
2114_LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
2115void atomic_wait_explicit(const atomic<_Tp>* __o,
2116 typename atomic<_Tp>::value_type __v,
2117 memory_order __m) _NOEXCEPT
2118 _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m)
2119{
2120 return __o->wait(__v, __m);
2121}
2122
2123// atomic_notify_one
2124
2125template <class _Tp>
2126_LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
2127void atomic_notify_one(volatile atomic<_Tp>* __o) _NOEXCEPT
2128{
2129 __o->notify_one();
2130}
2131template <class _Tp>
2132_LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
2133void atomic_notify_one(atomic<_Tp>* __o) _NOEXCEPT
2134{
2135 __o->notify_one();
2136}
2137
2138// atomic_notify_one
2139
2140template <class _Tp>
2141_LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
2142void atomic_notify_all(volatile atomic<_Tp>* __o) _NOEXCEPT
2143{
2144 __o->notify_all();
2145}
2146template <class _Tp>
2147_LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
2148void atomic_notify_all(atomic<_Tp>* __o) _NOEXCEPT
2149{
2150 __o->notify_all();
2151}
2152
19502153// atomic_fetch_add
19512154
19522155template <class _Tp>
......@@ -2279,6 +2482,13 @@ typedef struct atomic_flag
22792482{
22802483 __cxx_atomic_impl<_LIBCPP_ATOMIC_FLAG_TYPE> __a_;
22812484
2485 _LIBCPP_INLINE_VISIBILITY
2486 bool test(memory_order __m = memory_order_seq_cst) const volatile _NOEXCEPT
2487 {return _LIBCPP_ATOMIC_FLAG_TYPE(true) == __cxx_atomic_load(&__a_, __m);}
2488 _LIBCPP_INLINE_VISIBILITY
2489 bool test(memory_order __m = memory_order_seq_cst) const _NOEXCEPT
2490 {return _LIBCPP_ATOMIC_FLAG_TYPE(true) == __cxx_atomic_load(&__a_, __m);}
2491
22822492 _LIBCPP_INLINE_VISIBILITY
22832493 bool test_and_set(memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
22842494 {return __cxx_atomic_exchange(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(true), __m);}
......@@ -2292,6 +2502,25 @@ typedef struct atomic_flag
22922502 void clear(memory_order __m = memory_order_seq_cst) _NOEXCEPT
22932503 {__cxx_atomic_store(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(false), __m);}
22942504
2505 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
2506 void wait(bool __v, memory_order __m = memory_order_seq_cst) const volatile _NOEXCEPT
2507 {__cxx_atomic_wait(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(__v), __m);}
2508 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
2509 void wait(bool __v, memory_order __m = memory_order_seq_cst) const _NOEXCEPT
2510 {__cxx_atomic_wait(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(__v), __m);}
2511 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
2512 void notify_one() volatile _NOEXCEPT
2513 {__cxx_atomic_notify_one(&__a_);}
2514 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
2515 void notify_one() _NOEXCEPT
2516 {__cxx_atomic_notify_one(&__a_);}
2517 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
2518 void notify_all() volatile _NOEXCEPT
2519 {__cxx_atomic_notify_all(&__a_);}
2520 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
2521 void notify_all() _NOEXCEPT
2522 {__cxx_atomic_notify_all(&__a_);}
2523
22952524 _LIBCPP_INLINE_VISIBILITY
22962525 atomic_flag() _NOEXCEPT _LIBCPP_DEFAULT
22972526
......@@ -2304,12 +2533,44 @@ typedef struct atomic_flag
23042533 atomic_flag& operator=(const atomic_flag&) volatile = delete;
23052534#else
23062535private:
2536 _LIBCPP_INLINE_VISIBILITY
23072537 atomic_flag(const atomic_flag&);
2538 _LIBCPP_INLINE_VISIBILITY
23082539 atomic_flag& operator=(const atomic_flag&);
2540 _LIBCPP_INLINE_VISIBILITY
23092541 atomic_flag& operator=(const atomic_flag&) volatile;
23102542#endif
23112543} atomic_flag;
23122544
2545
2546inline _LIBCPP_INLINE_VISIBILITY
2547bool
2548atomic_flag_test(const volatile atomic_flag* __o) _NOEXCEPT
2549{
2550 return __o->test();
2551}
2552
2553inline _LIBCPP_INLINE_VISIBILITY
2554bool
2555atomic_flag_test(const atomic_flag* __o) _NOEXCEPT
2556{
2557 return __o->test();
2558}
2559
2560inline _LIBCPP_INLINE_VISIBILITY
2561bool
2562atomic_flag_test_explicit(const volatile atomic_flag* __o, memory_order __m) _NOEXCEPT
2563{
2564 return __o->test(__m);
2565}
2566
2567inline _LIBCPP_INLINE_VISIBILITY
2568bool
2569atomic_flag_test_explicit(const atomic_flag* __o, memory_order __m) _NOEXCEPT
2570{
2571 return __o->test(__m);
2572}
2573
23132574inline _LIBCPP_INLINE_VISIBILITY
23142575bool
23152576atomic_flag_test_and_set(volatile atomic_flag* __o) _NOEXCEPT
......@@ -2366,6 +2627,64 @@ atomic_flag_clear_explicit(atomic_flag* __o, memory_order __m) _NOEXCEPT
23662627 __o->clear(__m);
23672628}
23682629
2630inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_AVAILABILITY_SYNC
2631void
2632atomic_flag_wait(const volatile atomic_flag* __o, bool __v) _NOEXCEPT
2633{
2634 __o->wait(__v);
2635}
2636
2637inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_AVAILABILITY_SYNC
2638void
2639atomic_flag_wait(const atomic_flag* __o, bool __v) _NOEXCEPT
2640{
2641 __o->wait(__v);
2642}
2643
2644inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_AVAILABILITY_SYNC
2645void
2646atomic_flag_wait_explicit(const volatile atomic_flag* __o,
2647 bool __v, memory_order __m) _NOEXCEPT
2648{
2649 __o->wait(__v, __m);
2650}
2651
2652inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_AVAILABILITY_SYNC
2653void
2654atomic_flag_wait_explicit(const atomic_flag* __o,
2655 bool __v, memory_order __m) _NOEXCEPT
2656{
2657 __o->wait(__v, __m);
2658}
2659
2660inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_AVAILABILITY_SYNC
2661void
2662atomic_flag_notify_one(volatile atomic_flag* __o) _NOEXCEPT
2663{
2664 __o->notify_one();
2665}
2666
2667inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_AVAILABILITY_SYNC
2668void
2669atomic_flag_notify_one(atomic_flag* __o) _NOEXCEPT
2670{
2671 __o->notify_one();
2672}
2673
2674inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_AVAILABILITY_SYNC
2675void
2676atomic_flag_notify_all(volatile atomic_flag* __o) _NOEXCEPT
2677{
2678 __o->notify_all();
2679}
2680
2681inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_AVAILABILITY_SYNC
2682void
2683atomic_flag_notify_all(atomic_flag* __o) _NOEXCEPT
2684{
2685 __o->notify_all();
2686}
2687
23692688// fences
23702689
23712690inline _LIBCPP_INLINE_VISIBILITY
......@@ -2434,6 +2753,33 @@ typedef atomic<ptrdiff_t> atomic_ptrdiff_t;
24342753typedef atomic<intmax_t> atomic_intmax_t;
24352754typedef atomic<uintmax_t> atomic_uintmax_t;
24362755
2756// atomic_*_lock_free : prefer the contention type most highly, then the largest lock-free type
2757
2758#ifdef __cpp_lib_atomic_is_always_lock_free
2759# define _LIBCPP_CONTENTION_LOCK_FREE __atomic_always_lock_free(sizeof(__cxx_contention_t), 0)
2760#else
2761# define _LIBCPP_CONTENTION_LOCK_FREE false
2762#endif
2763
2764#if ATOMIC_LLONG_LOCK_FREE == 2
2765typedef conditional<_LIBCPP_CONTENTION_LOCK_FREE, __cxx_contention_t, long long>::type __libcpp_signed_lock_free;
2766typedef conditional<_LIBCPP_CONTENTION_LOCK_FREE, __cxx_contention_t, unsigned long long>::type __libcpp_unsigned_lock_free;
2767#elif ATOMIC_INT_LOCK_FREE == 2
2768typedef conditional<_LIBCPP_CONTENTION_LOCK_FREE, __cxx_contention_t, int>::type __libcpp_signed_lock_free;
2769typedef conditional<_LIBCPP_CONTENTION_LOCK_FREE, __cxx_contention_t, unsigned int>::type __libcpp_unsigned_lock_free;
2770#elif ATOMIC_SHORT_LOCK_FREE == 2
2771typedef conditional<_LIBCPP_CONTENTION_LOCK_FREE, __cxx_contention_t, short>::type __libcpp_signed_lock_free;
2772typedef conditional<_LIBCPP_CONTENTION_LOCK_FREE, __cxx_contention_t, unsigned short>::type __libcpp_unsigned_lock_free;
2773#elif ATOMIC_CHAR_LOCK_FREE == 2
2774typedef conditional<_LIBCPP_CONTENTION_LOCK_FREE, __cxx_contention_t, char>::type __libcpp_signed_lock_free;
2775typedef conditional<_LIBCPP_CONTENTION_LOCK_FREE, __cxx_contention_t, unsigned char>::type __libcpp_unsigned_lock_free;
2776#else
2777 // No signed/unsigned lock-free types
2778#endif
2779
2780typedef atomic<__libcpp_signed_lock_free> atomic_signed_lock_free;
2781typedef atomic<__libcpp_unsigned_lock_free> atomic_unsigned_lock_free;
2782
24372783#define ATOMIC_FLAG_INIT {false}
24382784#define ATOMIC_VAR_INIT(__v) {__v}
24392785
lib/libcxx/include/barrier created+322
......@@ -0,0 +1,322 @@
1// -*- C++ -*-
2//===--------------------------- barrier ----------------------------------===//
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_BARRIER
11#define _LIBCPP_BARRIER
12
13/*
14 barrier synopsis
15
16namespace std
17{
18
19 template<class CompletionFunction = see below>
20 class barrier
21 {
22 public:
23 using arrival_token = see below;
24
25 constexpr explicit barrier(ptrdiff_t phase_count,
26 CompletionFunction f = CompletionFunction());
27 ~barrier();
28
29 barrier(const barrier&) = delete;
30 barrier& operator=(const barrier&) = delete;
31
32 [[nodiscard]] arrival_token arrive(ptrdiff_t update = 1);
33 void wait(arrival_token&& arrival) const;
34
35 void arrive_and_wait();
36 void arrive_and_drop();
37
38 private:
39 CompletionFunction completion; // exposition only
40 };
41
42}
43
44*/
45
46#include <__config>
47#include <atomic>
48#ifndef _LIBCPP_HAS_NO_TREE_BARRIER
49# include <memory>
50#endif
51
52#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
53#pragma GCC system_header
54#endif
55
56#ifdef _LIBCPP_HAS_NO_THREADS
57# error <barrier> is not supported on this single threaded system
58#endif
59
60#if _LIBCPP_STD_VER >= 14
61
62_LIBCPP_BEGIN_NAMESPACE_STD
63
64struct __empty_completion
65{
66 inline _LIBCPP_INLINE_VISIBILITY
67 void operator()() noexcept
68 {
69 }
70};
71
72#ifndef _LIBCPP_HAS_NO_TREE_BARRIER
73
74/*
75
76The default implementation of __barrier_base is a classic tree barrier.
77
78It looks different from literature pseudocode for two main reasons:
79 1. Threads that call into std::barrier functions do not provide indices,
80 so a numbering step is added before the actual barrier algorithm,
81 appearing as an N+1 round to the N rounds of the tree barrier.
82 2. A great deal of attention has been paid to avoid cache line thrashing
83 by flattening the tree structure into cache-line sized arrays, that
84 are indexed in an efficient way.
85
86*/
87
88using __barrier_phase_t = uint8_t;
89
90class __barrier_algorithm_base;
91
92_LIBCPP_AVAILABILITY_SYNC _LIBCPP_EXPORTED_FROM_ABI
93__barrier_algorithm_base* __construct_barrier_algorithm_base(ptrdiff_t& __expected);
94
95_LIBCPP_AVAILABILITY_SYNC _LIBCPP_EXPORTED_FROM_ABI
96bool __arrive_barrier_algorithm_base(__barrier_algorithm_base* __barrier,
97 __barrier_phase_t __old_phase);
98
99_LIBCPP_AVAILABILITY_SYNC _LIBCPP_EXPORTED_FROM_ABI
100void __destroy_barrier_algorithm_base(__barrier_algorithm_base* __barrier);
101
102template<class _CompletionF>
103class __barrier_base {
104
105 ptrdiff_t __expected;
106 unique_ptr<__barrier_algorithm_base,
107 void (*)(__barrier_algorithm_base*)> __base;
108 __atomic_base<ptrdiff_t> __expected_adjustment;
109 _CompletionF __completion;
110 __atomic_base<__barrier_phase_t> __phase;
111
112public:
113 using arrival_token = __barrier_phase_t;
114
115 static constexpr ptrdiff_t max() noexcept {
116 return numeric_limits<ptrdiff_t>::max();
117 }
118
119 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
120 __barrier_base(ptrdiff_t __expected, _CompletionF __completion = _CompletionF())
121 : __expected(__expected), __base(__construct_barrier_algorithm_base(this->__expected),
122 &__destroy_barrier_algorithm_base),
123 __expected_adjustment(0), __completion(move(__completion)), __phase(0)
124 {
125 }
126 [[nodiscard]] _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
127 arrival_token arrive(ptrdiff_t update)
128 {
129 auto const __old_phase = __phase.load(memory_order_relaxed);
130 for(; update; --update)
131 if(__arrive_barrier_algorithm_base(__base.get(), __old_phase)) {
132 __completion();
133 __expected += __expected_adjustment.load(memory_order_relaxed);
134 __expected_adjustment.store(0, memory_order_relaxed);
135 __phase.store(__old_phase + 2, memory_order_release);
136 __phase.notify_all();
137 }
138 return __old_phase;
139 }
140 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
141 void wait(arrival_token&& __old_phase) const
142 {
143 auto const __test_fn = [=]() -> bool {
144 return __phase.load(memory_order_acquire) != __old_phase;
145 };
146 __libcpp_thread_poll_with_backoff(__test_fn, __libcpp_timed_backoff_policy());
147 }
148 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
149 void arrive_and_drop()
150 {
151 __expected_adjustment.fetch_sub(1, memory_order_relaxed);
152 (void)arrive(1);
153 }
154};
155
156#else
157
158/*
159
160The alternative implementation of __barrier_base is a central barrier.
161
162Two versions of this algorithm are provided:
163 1. A fairly straightforward implementation of the litterature for the
164 general case where the completion function is not empty.
165 2. An optimized implementation that exploits 2's complement arithmetic
166 and well-defined overflow in atomic arithmetic, to handle the phase
167 roll-over for free.
168
169*/
170
171template<class _CompletionF>
172class __barrier_base {
173
174 __atomic_base<ptrdiff_t> __expected;
175 __atomic_base<ptrdiff_t> __arrived;
176 _CompletionF __completion;
177 __atomic_base<bool> __phase;
178public:
179 using arrival_token = bool;
180
181 static constexpr ptrdiff_t max() noexcept {
182 return numeric_limits<ptrdiff_t>::max();
183 }
184
185 _LIBCPP_INLINE_VISIBILITY
186 __barrier_base(ptrdiff_t __expected, _CompletionF __completion = _CompletionF())
187 : __expected(__expected), __arrived(__expected), __completion(move(__completion)), __phase(false)
188 {
189 }
190 [[nodiscard]] _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
191 arrival_token arrive(ptrdiff_t update)
192 {
193 auto const __old_phase = __phase.load(memory_order_relaxed);
194 auto const __result = __arrived.fetch_sub(update, memory_order_acq_rel) - update;
195 auto const new_expected = __expected.load(memory_order_relaxed);
196 if(0 == __result) {
197 __completion();
198 __arrived.store(new_expected, memory_order_relaxed);
199 __phase.store(!__old_phase, memory_order_release);
200 __phase.notify_all();
201 }
202 return __old_phase;
203 }
204 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
205 void wait(arrival_token&& __old_phase) const
206 {
207 __phase.wait(__old_phase, memory_order_acquire);
208 }
209 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
210 void arrive_and_drop()
211 {
212 __expected.fetch_sub(1, memory_order_relaxed);
213 (void)arrive(1);
214 }
215};
216
217template<>
218class __barrier_base<__empty_completion> {
219
220 static constexpr uint64_t __expected_unit = 1ull;
221 static constexpr uint64_t __arrived_unit = 1ull << 32;
222 static constexpr uint64_t __expected_mask = __arrived_unit - 1;
223 static constexpr uint64_t __phase_bit = 1ull << 63;
224 static constexpr uint64_t __arrived_mask = (__phase_bit - 1) & ~__expected_mask;
225
226 __atomic_base<uint64_t> __phase_arrived_expected;
227
228 static _LIBCPP_INLINE_VISIBILITY
229 constexpr uint64_t __init(ptrdiff_t __count) _NOEXCEPT
230 {
231 return ((uint64_t(1u << 31) - __count) << 32)
232 | (uint64_t(1u << 31) - __count);
233 }
234
235public:
236 using arrival_token = uint64_t;
237
238 static constexpr ptrdiff_t max() noexcept {
239 return ptrdiff_t(1u << 31) - 1;
240 }
241
242 _LIBCPP_INLINE_VISIBILITY
243 explicit inline __barrier_base(ptrdiff_t __count, __empty_completion = __empty_completion())
244 : __phase_arrived_expected(__init(__count))
245 {
246 }
247 [[nodiscard]] inline _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
248 arrival_token arrive(ptrdiff_t update)
249 {
250 auto const __inc = __arrived_unit * update;
251 auto const __old = __phase_arrived_expected.fetch_add(__inc, memory_order_acq_rel);
252 if((__old ^ (__old + __inc)) & __phase_bit) {
253 __phase_arrived_expected.fetch_add((__old & __expected_mask) << 32, memory_order_relaxed);
254 __phase_arrived_expected.notify_all();
255 }
256 return __old & __phase_bit;
257 }
258 inline _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
259 void wait(arrival_token&& __phase) const
260 {
261 auto const __test_fn = [=]() -> bool {
262 uint64_t const __current = __phase_arrived_expected.load(memory_order_acquire);
263 return ((__current & __phase_bit) != __phase);
264 };
265 __libcpp_thread_poll_with_backoff(__test_fn, __libcpp_timed_backoff_policy());
266 }
267 inline _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
268 void arrive_and_drop()
269 {
270 __phase_arrived_expected.fetch_add(__expected_unit, memory_order_relaxed);
271 (void)arrive(1);
272 }
273};
274
275#endif //_LIBCPP_HAS_NO_TREE_BARRIER
276
277template<class _CompletionF = __empty_completion>
278class barrier {
279
280 __barrier_base<_CompletionF> __b;
281public:
282 using arrival_token = typename __barrier_base<_CompletionF>::arrival_token;
283
284 static constexpr ptrdiff_t max() noexcept {
285 return __barrier_base<_CompletionF>::max();
286 }
287
288 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
289 barrier(ptrdiff_t __count, _CompletionF __completion = _CompletionF())
290 : __b(__count, std::move(__completion)) {
291 }
292
293 barrier(barrier const&) = delete;
294 barrier& operator=(barrier const&) = delete;
295
296 [[nodiscard]] _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
297 arrival_token arrive(ptrdiff_t update = 1)
298 {
299 return __b.arrive(update);
300 }
301 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
302 void wait(arrival_token&& __phase) const
303 {
304 __b.wait(std::move(__phase));
305 }
306 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
307 void arrive_and_wait()
308 {
309 wait(arrive());
310 }
311 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
312 void arrive_and_drop()
313 {
314 __b.arrive_and_drop();
315 }
316};
317
318_LIBCPP_END_NAMESPACE_STD
319
320#endif // _LIBCPP_STD_VER >= 14
321
322#endif //_LIBCPP_BARRIER
lib/libcxx/include/bit+5-4
......@@ -15,6 +15,7 @@
1515
1616namespace std {
1717
18 // [bit.pow.two], integral powers of 2
1819 template <class T>
1920 constexpr bool ispow2(T x) noexcept; // C++20
2021 template <class T>
......@@ -24,13 +25,13 @@ namespace std {
2425 template <class T>
2526 constexpr T log2p1(T x) noexcept; // C++20
2627
27 // 23.20.2, rotating
28 // [bit.rotate], rotating
2829 template<class T>
2930 constexpr T rotl(T x, unsigned int s) noexcept; // C++20
3031 template<class T>
3132 constexpr T rotr(T x, unsigned int s) noexcept; // C++20
3233
33 // 23.20.3, counting
34 // [bit.count], counting
3435 template<class T>
3536 constexpr int countl_zero(T x) noexcept; // C++20
3637 template<class T>
......@@ -42,7 +43,7 @@ namespace std {
4243 template<class T>
4344 constexpr int popcount(T x) noexcept; // C++20
4445
45 // 20.15.9, endian
46 // [bit.endian], endian
4647 enum class endian {
4748 little = see below, // C++20
4849 big = see below, // C++20
......@@ -350,7 +351,7 @@ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
350351bool __ispow2(_Tp __t) _NOEXCEPT
351352{
352353 static_assert(__bitop_unsigned_integer<_Tp>::value, "__ispow2 requires unsigned");
353 return __t != 0 && (((__t & (__t - 1)) == 0));
354 return __t != 0 && (((__t & (__t - 1)) == 0));
354355}
355356
356357
lib/libcxx/include/charconv+11-2
......@@ -73,6 +73,7 @@ namespace std {
7373
7474*/
7575
76#include <__config>
7677#include <__errc>
7778#include <type_traits>
7879#include <limits>
......@@ -92,8 +93,8 @@ _LIBCPP_PUSH_MACROS
9293_LIBCPP_BEGIN_NAMESPACE_STD
9394
9495namespace __itoa {
95_LIBCPP_FUNC_VIS char* __u64toa(uint64_t __value, char* __buffer);
96_LIBCPP_FUNC_VIS char* __u32toa(uint32_t __value, char* __buffer);
96_LIBCPP_AVAILABILITY_TO_CHARS _LIBCPP_FUNC_VIS char* __u64toa(uint64_t __value, char* __buffer) _NOEXCEPT;
97_LIBCPP_AVAILABILITY_TO_CHARS _LIBCPP_FUNC_VIS char* __u32toa(uint32_t __value, char* __buffer) _NOEXCEPT;
9798}
9899
99100#ifndef _LIBCPP_CXX03_LANG
......@@ -167,6 +168,7 @@ struct _LIBCPP_HIDDEN __traits_base
167168 }
168169#endif
169170
171 _LIBCPP_AVAILABILITY_TO_CHARS
170172 static _LIBCPP_INLINE_VISIBILITY char* __convert(_Tp __v, char* __p)
171173 {
172174 return __u64toa(__v, __p);
......@@ -189,6 +191,7 @@ struct _LIBCPP_HIDDEN
189191 }
190192#endif
191193
194 _LIBCPP_AVAILABILITY_TO_CHARS
192195 static _LIBCPP_INLINE_VISIBILITY char* __convert(_Tp __v, char* __p)
193196 {
194197 return __u32toa(__v, __p);
......@@ -292,6 +295,7 @@ __to_unsigned(_Tp __x)
292295}
293296
294297template <typename _Tp>
298_LIBCPP_AVAILABILITY_TO_CHARS
295299inline _LIBCPP_INLINE_VISIBILITY to_chars_result
296300__to_chars_itoa(char* __first, char* __last, _Tp __value, true_type)
297301{
......@@ -306,6 +310,7 @@ __to_chars_itoa(char* __first, char* __last, _Tp __value, true_type)
306310}
307311
308312template <typename _Tp>
313_LIBCPP_AVAILABILITY_TO_CHARS
309314inline _LIBCPP_INLINE_VISIBILITY to_chars_result
310315__to_chars_itoa(char* __first, char* __last, _Tp __value, false_type)
311316{
......@@ -337,6 +342,7 @@ __to_chars_itoa(char* __first, char* __last, _Tp __value, false_type)
337342}
338343
339344template <typename _Tp>
345_LIBCPP_AVAILABILITY_TO_CHARS
340346inline _LIBCPP_INLINE_VISIBILITY to_chars_result
341347__to_chars_integral(char* __first, char* __last, _Tp __value, int __base,
342348 true_type)
......@@ -352,6 +358,7 @@ __to_chars_integral(char* __first, char* __last, _Tp __value, int __base,
352358}
353359
354360template <typename _Tp>
361_LIBCPP_AVAILABILITY_TO_CHARS
355362inline _LIBCPP_INLINE_VISIBILITY to_chars_result
356363__to_chars_integral(char* __first, char* __last, _Tp __value, int __base,
357364 false_type)
......@@ -380,6 +387,7 @@ __to_chars_integral(char* __first, char* __last, _Tp __value, int __base,
380387}
381388
382389template <typename _Tp, typename enable_if<is_integral<_Tp>::value, int>::type = 0>
390_LIBCPP_AVAILABILITY_TO_CHARS
383391inline _LIBCPP_INLINE_VISIBILITY to_chars_result
384392to_chars(char* __first, char* __last, _Tp __value)
385393{
......@@ -387,6 +395,7 @@ to_chars(char* __first, char* __last, _Tp __value)
387395}
388396
389397template <typename _Tp, typename enable_if<is_integral<_Tp>::value, int>::type = 0>
398_LIBCPP_AVAILABILITY_TO_CHARS
390399inline _LIBCPP_INLINE_VISIBILITY to_chars_result
391400to_chars(char* __first, char* __last, _Tp __value, int __base)
392401{
lib/libcxx/include/chrono+1-1
......@@ -2454,7 +2454,7 @@ chrono::day year_month_day_last::day() const noexcept
24542454 chrono::day(31), chrono::day(31), chrono::day(30),
24552455 chrono::day(31), chrono::day(30), chrono::day(31)
24562456 };
2457 return month() != February || !__y.is_leap() ?
2457 return (month() != February || !__y.is_leap()) && month().ok() ?
24582458 __d[static_cast<unsigned>(month()) - 1] : chrono::day{29};
24592459}
24602460
lib/libcxx/include/cmath+4
......@@ -296,6 +296,10 @@ floating_point trunc (arithmetic x);
296296float truncf(float x);
297297long double truncl(long double x);
298298
299constexpr float lerp(float a, float b, float t) noexcept; // C++20
300constexpr double lerp(double a, double b, double t) noexcept; // C++20
301constexpr long double lerp(long double a, long double b, long double t) noexcept; // C++20
302
299303} // std
300304
301305*/
lib/libcxx/include/codecvt+36-36
......@@ -102,11 +102,11 @@ protected:
102102 virtual result
103103 do_unshift(state_type& __st,
104104 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
105 virtual int do_encoding() const throw();
106 virtual bool do_always_noconv() const throw();
105 virtual int do_encoding() const _NOEXCEPT;
106 virtual bool do_always_noconv() const _NOEXCEPT;
107107 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
108108 size_t __mx) const;
109 virtual int do_max_length() const throw();
109 virtual int do_max_length() const _NOEXCEPT;
110110};
111111
112112template <>
......@@ -137,11 +137,11 @@ protected:
137137 virtual result
138138 do_unshift(state_type& __st,
139139 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
140 virtual int do_encoding() const throw();
141 virtual bool do_always_noconv() const throw();
140 virtual int do_encoding() const _NOEXCEPT;
141 virtual bool do_always_noconv() const _NOEXCEPT;
142142 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
143143 size_t __mx) const;
144 virtual int do_max_length() const throw();
144 virtual int do_max_length() const _NOEXCEPT;
145145};
146146
147147template <>
......@@ -172,11 +172,11 @@ protected:
172172 virtual result
173173 do_unshift(state_type& __st,
174174 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
175 virtual int do_encoding() const throw();
176 virtual bool do_always_noconv() const throw();
175 virtual int do_encoding() const _NOEXCEPT;
176 virtual bool do_always_noconv() const _NOEXCEPT;
177177 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
178178 size_t __mx) const;
179 virtual int do_max_length() const throw();
179 virtual int do_max_length() const _NOEXCEPT;
180180};
181181
182182template <class _Elem, unsigned long _Maxcode = 0x10ffff,
......@@ -225,11 +225,11 @@ protected:
225225 virtual result
226226 do_unshift(state_type& __st,
227227 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
228 virtual int do_encoding() const throw();
229 virtual bool do_always_noconv() const throw();
228 virtual int do_encoding() const _NOEXCEPT;
229 virtual bool do_always_noconv() const _NOEXCEPT;
230230 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
231231 size_t __mx) const;
232 virtual int do_max_length() const throw();
232 virtual int do_max_length() const _NOEXCEPT;
233233};
234234
235235template <>
......@@ -260,11 +260,11 @@ protected:
260260 virtual result
261261 do_unshift(state_type& __st,
262262 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
263 virtual int do_encoding() const throw();
264 virtual bool do_always_noconv() const throw();
263 virtual int do_encoding() const _NOEXCEPT;
264 virtual bool do_always_noconv() const _NOEXCEPT;
265265 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
266266 size_t __mx) const;
267 virtual int do_max_length() const throw();
267 virtual int do_max_length() const _NOEXCEPT;
268268};
269269
270270template <>
......@@ -295,11 +295,11 @@ protected:
295295 virtual result
296296 do_unshift(state_type& __st,
297297 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
298 virtual int do_encoding() const throw();
299 virtual bool do_always_noconv() const throw();
298 virtual int do_encoding() const _NOEXCEPT;
299 virtual bool do_always_noconv() const _NOEXCEPT;
300300 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
301301 size_t __mx) const;
302 virtual int do_max_length() const throw();
302 virtual int do_max_length() const _NOEXCEPT;
303303};
304304
305305template <>
......@@ -330,11 +330,11 @@ protected:
330330 virtual result
331331 do_unshift(state_type& __st,
332332 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
333 virtual int do_encoding() const throw();
334 virtual bool do_always_noconv() const throw();
333 virtual int do_encoding() const _NOEXCEPT;
334 virtual bool do_always_noconv() const _NOEXCEPT;
335335 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
336336 size_t __mx) const;
337 virtual int do_max_length() const throw();
337 virtual int do_max_length() const _NOEXCEPT;
338338};
339339
340340template <>
......@@ -365,11 +365,11 @@ protected:
365365 virtual result
366366 do_unshift(state_type& __st,
367367 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
368 virtual int do_encoding() const throw();
369 virtual bool do_always_noconv() const throw();
368 virtual int do_encoding() const _NOEXCEPT;
369 virtual bool do_always_noconv() const _NOEXCEPT;
370370 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
371371 size_t __mx) const;
372 virtual int do_max_length() const throw();
372 virtual int do_max_length() const _NOEXCEPT;
373373};
374374
375375template <>
......@@ -400,11 +400,11 @@ protected:
400400 virtual result
401401 do_unshift(state_type& __st,
402402 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
403 virtual int do_encoding() const throw();
404 virtual bool do_always_noconv() const throw();
403 virtual int do_encoding() const _NOEXCEPT;
404 virtual bool do_always_noconv() const _NOEXCEPT;
405405 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
406406 size_t __mx) const;
407 virtual int do_max_length() const throw();
407 virtual int do_max_length() const _NOEXCEPT;
408408};
409409
410410template <class _Elem, unsigned long _Maxcode = 0x10ffff,
......@@ -453,11 +453,11 @@ protected:
453453 virtual result
454454 do_unshift(state_type& __st,
455455 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
456 virtual int do_encoding() const throw();
457 virtual bool do_always_noconv() const throw();
456 virtual int do_encoding() const _NOEXCEPT;
457 virtual bool do_always_noconv() const _NOEXCEPT;
458458 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
459459 size_t __mx) const;
460 virtual int do_max_length() const throw();
460 virtual int do_max_length() const _NOEXCEPT;
461461};
462462
463463template <>
......@@ -488,11 +488,11 @@ protected:
488488 virtual result
489489 do_unshift(state_type& __st,
490490 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
491 virtual int do_encoding() const throw();
492 virtual bool do_always_noconv() const throw();
491 virtual int do_encoding() const _NOEXCEPT;
492 virtual bool do_always_noconv() const _NOEXCEPT;
493493 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
494494 size_t __mx) const;
495 virtual int do_max_length() const throw();
495 virtual int do_max_length() const _NOEXCEPT;
496496};
497497
498498template <>
......@@ -523,11 +523,11 @@ protected:
523523 virtual result
524524 do_unshift(state_type& __st,
525525 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
526 virtual int do_encoding() const throw();
527 virtual bool do_always_noconv() const throw();
526 virtual int do_encoding() const _NOEXCEPT;
527 virtual bool do_always_noconv() const _NOEXCEPT;
528528 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
529529 size_t __mx) const;
530 virtual int do_max_length() const throw();
530 virtual int do_max_length() const _NOEXCEPT;
531531};
532532
533533template <class _Elem, unsigned long _Maxcode = 0x10ffff,
lib/libcxx/include/compare+84
......@@ -43,6 +43,84 @@ namespace std {
4343 template<class T> constexpr partial_ordering partial_order(const T& a, const T& b);
4444 template<class T> constexpr strong_equality strong_equal(const T& a, const T& b);
4545 template<class T> constexpr weak_equality weak_equal(const T& a, const T& b);
46
47 // [cmp.partialord], Class partial_ordering
48 class partial_ordering {
49 public:
50 // valid values
51 static const partial_ordering less;
52 static const partial_ordering equivalent;
53 static const partial_ordering greater;
54 static const partial_ordering unordered;
55
56 // comparisons
57 friend constexpr bool operator==(partial_ordering v, unspecified) noexcept;
58 friend constexpr bool operator==(partial_ordering v, partial_ordering w) noexcept = default;
59 friend constexpr bool operator< (partial_ordering v, unspecified) noexcept;
60 friend constexpr bool operator> (partial_ordering v, unspecified) noexcept;
61 friend constexpr bool operator<=(partial_ordering v, unspecified) noexcept;
62 friend constexpr bool operator>=(partial_ordering v, unspecified) noexcept;
63 friend constexpr bool operator< (unspecified, partial_ordering v) noexcept;
64 friend constexpr bool operator> (unspecified, partial_ordering v) noexcept;
65 friend constexpr bool operator<=(unspecified, partial_ordering v) noexcept;
66 friend constexpr bool operator>=(unspecified, partial_ordering v) noexcept;
67 friend constexpr partial_ordering operator<=>(partial_ordering v, unspecified) noexcept;
68 friend constexpr partial_ordering operator<=>(unspecified, partial_ordering v) noexcept;
69 };
70
71 // [cmp.weakord], Class weak_ordering
72 class weak_ordering {
73 public:
74 // valid values
75 static const weak_ordering less;
76 static const weak_ordering equivalent;
77 static const weak_ordering greater;
78
79 // conversions
80 constexpr operator partial_ordering() const noexcept;
81
82 // comparisons
83 friend constexpr bool operator==(weak_ordering v, unspecified) noexcept;
84 friend constexpr bool operator==(weak_ordering v, weak_ordering w) noexcept = default;
85 friend constexpr bool operator< (weak_ordering v, unspecified) noexcept;
86 friend constexpr bool operator> (weak_ordering v, unspecified) noexcept;
87 friend constexpr bool operator<=(weak_ordering v, unspecified) noexcept;
88 friend constexpr bool operator>=(weak_ordering v, unspecified) noexcept;
89 friend constexpr bool operator< (unspecified, weak_ordering v) noexcept;
90 friend constexpr bool operator> (unspecified, weak_ordering v) noexcept;
91 friend constexpr bool operator<=(unspecified, weak_ordering v) noexcept;
92 friend constexpr bool operator>=(unspecified, weak_ordering v) noexcept;
93 friend constexpr weak_ordering operator<=>(weak_ordering v, unspecified) noexcept;
94 friend constexpr weak_ordering operator<=>(unspecified, weak_ordering v) noexcept;
95 };
96
97 // [cmp.strongord], Class strong_ordering
98 class strong_ordering {
99 public:
100 // valid values
101 static const strong_ordering less;
102 static const strong_ordering equal;
103 static const strong_ordering equivalent;
104 static const strong_ordering greater;
105
106 // conversions
107 constexpr operator partial_ordering() const noexcept;
108 constexpr operator weak_ordering() const noexcept;
109
110 // comparisons
111 friend constexpr bool operator==(strong_ordering v, unspecified) noexcept;
112 friend constexpr bool operator==(strong_ordering v, strong_ordering w) noexcept = default;
113 friend constexpr bool operator< (strong_ordering v, unspecified) noexcept;
114 friend constexpr bool operator> (strong_ordering v, unspecified) noexcept;
115 friend constexpr bool operator<=(strong_ordering v, unspecified) noexcept;
116 friend constexpr bool operator>=(strong_ordering v, unspecified) noexcept;
117 friend constexpr bool operator< (unspecified, strong_ordering v) noexcept;
118 friend constexpr bool operator> (unspecified, strong_ordering v) noexcept;
119 friend constexpr bool operator<=(unspecified, strong_ordering v) noexcept;
120 friend constexpr bool operator>=(unspecified, strong_ordering v) noexcept;
121 friend constexpr strong_ordering operator<=>(strong_ordering v, unspecified) noexcept;
122 friend constexpr strong_ordering operator<=>(unspecified, strong_ordering v) noexcept;
123 };
46124}
47125*/
48126
......@@ -248,6 +326,8 @@ public:
248326 _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator>=(_CmpUnspecifiedParam, partial_ordering __v) noexcept;
249327
250328#ifndef _LIBCPP_HAS_NO_SPACESHIP_OPERATOR
329 _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(partial_ordering, partial_ordering) noexcept = default;
330
251331 _LIBCPP_INLINE_VISIBILITY friend constexpr partial_ordering operator<=>(partial_ordering __v, _CmpUnspecifiedParam) noexcept;
252332 _LIBCPP_INLINE_VISIBILITY friend constexpr partial_ordering operator<=>(_CmpUnspecifiedParam, partial_ordering __v) noexcept;
253333#endif
......@@ -364,6 +444,8 @@ public:
364444 _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator>=(_CmpUnspecifiedParam, weak_ordering __v) noexcept;
365445
366446#ifndef _LIBCPP_HAS_NO_SPACESHIP_OPERATOR
447 _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(weak_ordering, weak_ordering) noexcept = default;
448
367449 _LIBCPP_INLINE_VISIBILITY friend constexpr weak_ordering operator<=>(weak_ordering __v, _CmpUnspecifiedParam) noexcept;
368450 _LIBCPP_INLINE_VISIBILITY friend constexpr weak_ordering operator<=>(_CmpUnspecifiedParam, weak_ordering __v) noexcept;
369451#endif
......@@ -490,6 +572,8 @@ public:
490572 _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator>=(_CmpUnspecifiedParam, strong_ordering __v) noexcept;
491573
492574#ifndef _LIBCPP_HAS_NO_SPACESHIP_OPERATOR
575 _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(strong_ordering, strong_ordering) noexcept = default;
576
493577 _LIBCPP_INLINE_VISIBILITY friend constexpr strong_ordering operator<=>(strong_ordering __v, _CmpUnspecifiedParam) noexcept;
494578 _LIBCPP_INLINE_VISIBILITY friend constexpr strong_ordering operator<=>(_CmpUnspecifiedParam, strong_ordering __v) noexcept;
495579#endif
lib/libcxx/include/complex+7-6
......@@ -243,6 +243,7 @@ template<class T, class charT, class traits>
243243#include <type_traits>
244244#include <stdexcept>
245245#include <cmath>
246#include <iosfwd>
246247#include <sstream>
247248#include <version>
248249
......@@ -1406,10 +1407,10 @@ operator>>(basic_istream<_CharT, _Traits>& __is, complex<_Tp>& __x)
14061407 __x = complex<_Tp>(__r, __i);
14071408 }
14081409 else
1409 __is.setstate(ios_base::failbit);
1410 __is.setstate(__is.failbit);
14101411 }
14111412 else
1412 __is.setstate(ios_base::failbit);
1413 __is.setstate(__is.failbit);
14131414 }
14141415 else if (__c == _CharT(')'))
14151416 {
......@@ -1417,10 +1418,10 @@ operator>>(basic_istream<_CharT, _Traits>& __is, complex<_Tp>& __x)
14171418 __x = complex<_Tp>(__r, _Tp(0));
14181419 }
14191420 else
1420 __is.setstate(ios_base::failbit);
1421 __is.setstate(__is.failbit);
14211422 }
14221423 else
1423 __is.setstate(ios_base::failbit);
1424 __is.setstate(__is.failbit);
14241425 }
14251426 else
14261427 {
......@@ -1429,11 +1430,11 @@ operator>>(basic_istream<_CharT, _Traits>& __is, complex<_Tp>& __x)
14291430 if (!__is.fail())
14301431 __x = complex<_Tp>(__r, _Tp(0));
14311432 else
1432 __is.setstate(ios_base::failbit);
1433 __is.setstate(__is.failbit);
14331434 }
14341435 }
14351436 else
1436 __is.setstate(ios_base::failbit);
1437 __is.setstate(__is.failbit);
14371438 return __is;
14381439}
14391440
lib/libcxx/include/concepts created+166
......@@ -0,0 +1,166 @@
1// -*- C++ -*-
2//===-------------------------- concepts ----------------------------------===//
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_CONCEPTS
11#define _LIBCPP_CONCEPTS
12
13/*
14 concepts synopsis
15namespace std {
16 // [concepts.lang], language-related concepts
17 // [concept.same], concept same_as
18 template<class T, class U>
19 concept same_as = see below;
20
21 // [concept.derived], concept derived_from
22 template<class Derived, class Base>
23 concept derived_from = see below;
24
25 // [concept.convertible], concept convertible_to
26 template<class From, class To>
27 concept convertible_to = see below;
28
29 // [concept.commonref], concept common_reference_with
30 template<class T, class U>
31 concept common_reference_with = see below;
32
33 // [concept.common], concept common_with
34 template<class T, class U>
35 concept common_with = see below;
36
37 // [concepts.arithmetic], arithmetic concepts
38 template<class T>
39 concept integral = see below;
40 template<class T>
41 concept signed_integral = see below;
42 template<class T>
43 concept unsigned_integral = see below;
44 template<class T>
45 concept floating_point = see below;
46
47 // [concept.assignable], concept assignable_from
48 template<class LHS, class RHS>
49 concept assignable_from = see below;
50
51 // [concept.swappable], concept swappable
52 namespace ranges {
53 inline namespace unspecified {
54 inline constexpr unspecified swap = unspecified;
55 }
56 }
57 template<class T>
58 concept swappable = see below;
59 template<class T, class U>
60 concept swappable_with = see below;
61
62 // [concept.destructible], concept destructible
63 template<class T>
64 concept destructible = see below;
65
66 // [concept.constructible], concept constructible_from
67 template<class T, class... Args>
68 concept constructible_from = see below;
69
70 // [concept.defaultconstructible], concept default_constructible
71 template<class T>
72 concept default_constructible = see below;
73
74 // [concept.moveconstructible], concept move_constructible
75 template<class T>
76 concept move_constructible = see below;
77
78 // [concept.copyconstructible], concept copy_constructible
79 template<class T>
80 concept copy_constructible = see below;
81
82 // [concepts.compare], comparison concepts
83 // [concept.boolean], concept boolean
84 template<class B>
85 concept boolean = see below;
86
87 // [concept.equalitycomparable], concept equality_comparable
88 template<class T>
89 concept equality_comparable = see below;
90 template<class T, class U>
91 concept equality_comparable_with = see below;
92
93 // [concept.totallyordered], concept totally_ordered
94 template<class T>
95 concept totally_ordered = see below;
96 template<class T, class U>
97 concept totally_ordered_with = see below;
98
99 // [concepts.object], object concepts
100 template<class T>
101 concept movable = see below;
102 template<class T>
103 concept copyable = see below;
104 template<class T>
105 concept semiregular = see below;
106 template<class T>
107 concept regular = see below;
108
109 // [concepts.callable], callable concepts
110 // [concept.invocable], concept invocable
111 template<class F, class... Args>
112 concept invocable = see below;
113
114 // [concept.regularinvocable], concept regular_invocable
115 template<class F, class... Args>
116 concept regular_invocable = see below;
117
118 // [concept.predicate], concept predicate
119 template<class F, class... Args>
120 concept predicate = see below;
121
122 // [concept.relation], concept relation
123 template<class R, class T, class U>
124 concept relation = see below;
125
126 // [concept.equiv], concept equivalence_relation
127 template<class R, class T, class U>
128 concept equivalence_relation = see below;
129
130 // [concept.strictweakorder], concept strict_weak_order
131 template<class R, class T, class U>
132 concept strict_weak_order = see below;
133}
134
135*/
136
137#include <__config>
138#include <type_traits>
139#include <version>
140
141#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
142#pragma GCC system_header
143#endif
144
145_LIBCPP_PUSH_MACROS
146#include <__undef_macros>
147
148_LIBCPP_BEGIN_NAMESPACE_STD
149
150#if _LIBCPP_STD_VER > 17 && defined(__cpp_concepts) && __cpp_concepts >= 201811L
151
152// [concept.same]
153
154template<class _Tp, class _Up>
155concept __same_as_impl = _VSTD::_IsSame<_Tp, _Up>::value;
156
157template<class _Tp, class _Up>
158concept same_as = __same_as_impl<_Tp, _Up> && __same_as_impl<_Up, _Tp>;
159
160#endif //_LIBCPP_STD_VER > 17 && defined(__cpp_concepts) && __cpp_concepts >= 201811L
161
162_LIBCPP_END_NAMESPACE_STD
163
164_LIBCPP_POP_MACROS
165
166#endif // _LIBCPP_CONCEPTS
lib/libcxx/include/cstddef+56-8
......@@ -25,7 +25,7 @@ Types:
2525
2626 ptrdiff_t
2727 size_t
28 max_align_t
28 max_align_t // C++11
2929 nullptr_t
3030 byte // C++17
3131
......@@ -49,12 +49,34 @@ _LIBCPP_BEGIN_NAMESPACE_STD
4949using ::ptrdiff_t;
5050using ::size_t;
5151
52#if defined(__CLANG_MAX_ALIGN_T_DEFINED) || defined(_GCC_MAX_ALIGN_T) || \
53 defined(__DEFINED_max_align_t) || defined(__NetBSD__)
54// Re-use the compiler's <stddef.h> max_align_t where possible.
52#if !defined(_LIBCPP_CXX03_LANG)
5553using ::max_align_t;
56#else
57typedef long double max_align_t;
54#endif
55
56template <class _Tp> struct __libcpp_is_integral { enum { value = 0 }; };
57template <> struct __libcpp_is_integral<bool> { enum { value = 1 }; };
58template <> struct __libcpp_is_integral<char> { enum { value = 1 }; };
59template <> struct __libcpp_is_integral<signed char> { enum { value = 1 }; };
60template <> struct __libcpp_is_integral<unsigned char> { enum { value = 1 }; };
61template <> struct __libcpp_is_integral<wchar_t> { enum { value = 1 }; };
62#ifndef _LIBCPP_NO_HAS_CHAR8_T
63template <> struct __libcpp_is_integral<char8_t> { enum { value = 1 }; };
64#endif
65#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
66template <> struct __libcpp_is_integral<char16_t> { enum { value = 1 }; };
67template <> struct __libcpp_is_integral<char32_t> { enum { value = 1 }; };
68#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
69template <> struct __libcpp_is_integral<short> { enum { value = 1 }; };
70template <> struct __libcpp_is_integral<unsigned short> { enum { value = 1 }; };
71template <> struct __libcpp_is_integral<int> { enum { value = 1 }; };
72template <> struct __libcpp_is_integral<unsigned int> { enum { value = 1 }; };
73template <> struct __libcpp_is_integral<long> { enum { value = 1 }; };
74template <> struct __libcpp_is_integral<unsigned long> { enum { value = 1 }; };
75template <> struct __libcpp_is_integral<long long> { enum { value = 1 }; };
76template <> struct __libcpp_is_integral<unsigned long long> { enum { value = 1 }; };
77#ifndef _LIBCPP_HAS_NO_INT128
78template <> struct __libcpp_is_integral<__int128_t> { enum { value = 1 }; };
79template <> struct __libcpp_is_integral<__uint128_t> { enum { value = 1 }; };
5880#endif
5981
6082_LIBCPP_END_NAMESPACE_STD
......@@ -64,6 +86,11 @@ namespace std // purposefully not versioned
6486{
6587enum class byte : unsigned char {};
6688
89
90template <bool> struct __enable_if_integral_imp {};
91template <> struct __enable_if_integral_imp<true> { using type = byte; };
92template <class _Tp> using _EnableByteOverload = typename __enable_if_integral_imp<__libcpp_is_integral<_Tp>::value>::type;
93
6794constexpr byte operator| (byte __lhs, byte __rhs) noexcept
6895{
6996 return static_cast<byte>(
......@@ -104,10 +131,31 @@ constexpr byte operator~ (byte __b) noexcept
104131 ~static_cast<unsigned int>(__b)
105132 ));
106133}
107
134template <class _Integer>
135 constexpr _EnableByteOverload<_Integer> &
136 operator<<=(byte& __lhs, _Integer __shift) noexcept
137 { return __lhs = __lhs << __shift; }
138
139template <class _Integer>
140 constexpr _EnableByteOverload<_Integer>
141 operator<< (byte __lhs, _Integer __shift) noexcept
142 { return static_cast<byte>(static_cast<unsigned char>(static_cast<unsigned int>(__lhs) << __shift)); }
143
144template <class _Integer>
145 constexpr _EnableByteOverload<_Integer> &
146 operator>>=(byte& __lhs, _Integer __shift) noexcept
147 { return __lhs = __lhs >> __shift; }
148
149template <class _Integer>
150 constexpr _EnableByteOverload<_Integer>
151 operator>> (byte __lhs, _Integer __shift) noexcept
152 { return static_cast<byte>(static_cast<unsigned char>(static_cast<unsigned int>(__lhs) >> __shift)); }
153
154template <class _Integer, class = _EnableByteOverload<_Integer> >
155 constexpr _Integer
156 to_integer(byte __b) noexcept { return static_cast<_Integer>(__b); }
108157}
109158
110#include <type_traits> // rest of byte
111159#endif
112160
113161#endif // _LIBCPP_CSTDDEF
lib/libcxx/include/cstdio+4
......@@ -131,9 +131,13 @@ using ::putc;
131131using ::ungetc;
132132using ::fread;
133133using ::fwrite;
134#ifndef _LIBCPP_HAS_NO_FGETPOS_FSETPOS
134135using ::fgetpos;
136#endif
135137using ::fseek;
138#ifndef _LIBCPP_HAS_NO_FGETPOS_FSETPOS
136139using ::fsetpos;
140#endif
137141using ::ftell;
138142using ::rewind;
139143using ::clearerr;
lib/libcxx/include/deque+16-8
......@@ -150,9 +150,11 @@ template <class T, class Allocator>
150150 noexcept(noexcept(x.swap(y)));
151151
152152template <class T, class Allocator, class U>
153 void erase(deque<T, Allocator>& c, const U& value); // C++20
153 typename deque<T, Allocator>::size_type
154 erase(deque<T, Allocator>& c, const U& value); // C++20
154155template <class T, class Allocator, class Predicate>
155 void erase_if(deque<T, Allocator>& c, Predicate pred); // C++20
156 typename deque<T, Allocator>::size_type
157 erase_if(deque<T, Allocator>& c, Predicate pred); // C++20
156158
157159} // std
158160
......@@ -3021,14 +3023,20 @@ swap(deque<_Tp, _Allocator>& __x, deque<_Tp, _Allocator>& __y)
30213023
30223024#if _LIBCPP_STD_VER > 17
30233025template <class _Tp, class _Allocator, class _Up>
3024inline _LIBCPP_INLINE_VISIBILITY
3025void erase(deque<_Tp, _Allocator>& __c, const _Up& __v)
3026{ __c.erase(_VSTD::remove(__c.begin(), __c.end(), __v), __c.end()); }
3026inline _LIBCPP_INLINE_VISIBILITY typename deque<_Tp, _Allocator>::size_type
3027erase(deque<_Tp, _Allocator>& __c, const _Up& __v) {
3028 auto __old_size = __c.size();
3029 __c.erase(_VSTD::remove(__c.begin(), __c.end(), __v), __c.end());
3030 return __old_size - __c.size();
3031}
30273032
30283033template <class _Tp, class _Allocator, class _Predicate>
3029inline _LIBCPP_INLINE_VISIBILITY
3030void erase_if(deque<_Tp, _Allocator>& __c, _Predicate __pred)
3031{ __c.erase(_VSTD::remove_if(__c.begin(), __c.end(), __pred), __c.end()); }
3034inline _LIBCPP_INLINE_VISIBILITY typename deque<_Tp, _Allocator>::size_type
3035erase_if(deque<_Tp, _Allocator>& __c, _Predicate __pred) {
3036 auto __old_size = __c.size();
3037 __c.erase(_VSTD::remove_if(__c.begin(), __c.end(), __pred), __c.end());
3038 return __old_size - __c.size();
3039}
30323040#endif
30333041
30343042
lib/libcxx/include/exception+2
......@@ -98,6 +98,8 @@ class _LIBCPP_EXCEPTION_ABI exception
9898{
9999public:
100100 _LIBCPP_INLINE_VISIBILITY exception() _NOEXCEPT {}
101 _LIBCPP_INLINE_VISIBILITY exception(const exception&) _NOEXCEPT = default;
102
101103 virtual ~exception() _NOEXCEPT;
102104 virtual const char* what() const _NOEXCEPT;
103105};
lib/libcxx/include/filesystem+1
......@@ -1346,6 +1346,7 @@ public:
13461346 _LIBCPP_INLINE_VISIBILITY
13471347 const path& path2() const noexcept { return __storage_->__p2_; }
13481348
1349 filesystem_error(const filesystem_error&) = default;
13491350 ~filesystem_error() override; // key function
13501351
13511352 _LIBCPP_INLINE_VISIBILITY
lib/libcxx/include/forward_list+12-6
......@@ -169,9 +169,11 @@ template <class T, class Allocator>
169169 noexcept(noexcept(x.swap(y)));
170170
171171template <class T, class Allocator, class U>
172 void erase(forward_list<T, Allocator>& c, const U& value); // C++20
172 typename forward_list<T, Allocator>::size_type
173 erase(forward_list<T, Allocator>& c, const U& value); // C++20
173174template <class T, class Allocator, class Predicate>
174 void erase_if(forward_list<T, Allocator>& c, Predicate pred); // C++20
175 typename forward_list<T, Allocator>::size_type
176 erase_if(forward_list<T, Allocator>& c, Predicate pred); // C++20
175177
176178} // std
177179
......@@ -1765,13 +1767,17 @@ swap(forward_list<_Tp, _Alloc>& __x, forward_list<_Tp, _Alloc>& __y)
17651767#if _LIBCPP_STD_VER > 17
17661768template <class _Tp, class _Allocator, class _Predicate>
17671769inline _LIBCPP_INLINE_VISIBILITY
1768void erase_if(forward_list<_Tp, _Allocator>& __c, _Predicate __pred)
1769{ __c.remove_if(__pred); }
1770 typename forward_list<_Tp, _Allocator>::size_type
1771 erase_if(forward_list<_Tp, _Allocator>& __c, _Predicate __pred) {
1772 return __c.remove_if(__pred);
1773}
17701774
17711775template <class _Tp, class _Allocator, class _Up>
17721776inline _LIBCPP_INLINE_VISIBILITY
1773void erase(forward_list<_Tp, _Allocator>& __c, const _Up& __v)
1774{ _VSTD::erase_if(__c, [&](auto& __elem) { return __elem == __v; }); }
1777 typename forward_list<_Tp, _Allocator>::size_type
1778 erase(forward_list<_Tp, _Allocator>& __c, const _Up& __v) {
1779 return _VSTD::erase_if(__c, [&](auto& __elem) { return __elem == __v; });
1780}
17751781#endif
17761782
17771783_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/functional+112-25
......@@ -508,6 +508,10 @@ POLICY: For non-variadic implementations, the number of arguments is limited
508508
509509#include <__functional_base>
510510
511#if defined(_LIBCPP_HAS_BLOCKS_RUNTIME) && !defined(_LIBCPP_HAS_OBJC_ARC)
512#include <Block.h>
513#endif
514
511515#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
512516#pragma GCC system_header
513517#endif
......@@ -1434,7 +1438,14 @@ void __throw_bad_function_call()
14341438#endif
14351439}
14361440
1437template<class _Fp> class _LIBCPP_TEMPLATE_VIS function; // undefined
1441#if defined(_LIBCPP_CXX03_LANG) && !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS) && __has_attribute(deprecated)
1442# define _LIBCPP_DEPRECATED_CXX03_FUNCTION \
1443 __attribute__((deprecated("Using std::function in C++03 is not supported anymore. Please upgrade to C++11 or later, or use a different type")))
1444#else
1445# define _LIBCPP_DEPRECATED_CXX03_FUNCTION /* nothing */
1446#endif
1447
1448template<class _Fp> class _LIBCPP_DEPRECATED_CXX03_FUNCTION _LIBCPP_TEMPLATE_VIS function; // undefined
14381449
14391450namespace __function
14401451{
......@@ -1477,6 +1488,12 @@ template <class _Fp>
14771488_LIBCPP_INLINE_VISIBILITY
14781489bool __not_null(function<_Fp> const& __f) { return !!__f; }
14791490
1491#ifdef _LIBCPP_HAS_EXTENSION_BLOCKS
1492template <class _Rp, class ..._Args>
1493_LIBCPP_INLINE_VISIBILITY
1494bool __not_null(_Rp (^__p)(_Args...)) { return __p; }
1495#endif
1496
14801497} // namespace __function
14811498
14821499#ifndef _LIBCPP_CXX03_LANG
......@@ -1611,7 +1628,7 @@ public:
16111628
16121629// __base provides an abstract interface for copyable functors.
16131630
1614template<class _Fp> class __base;
1631template<class _Fp> class _LIBCPP_TEMPLATE_VIS __base;
16151632
16161633template<class _Rp, class ..._ArgTypes>
16171634class __base<_Rp(_ArgTypes...)>
......@@ -2238,6 +2255,72 @@ template <class _Rp, class... _ArgTypes> class __policy_func<_Rp(_ArgTypes...)>
22382255#endif // _LIBCPP_NO_RTTI
22392256};
22402257
2258#if defined(_LIBCPP_HAS_BLOCKS_RUNTIME) && !defined(_LIBCPP_HAS_OBJC_ARC)
2259
2260template<class _Rp1, class ..._ArgTypes1, class _Alloc, class _Rp, class ..._ArgTypes>
2261class __func<_Rp1(^)(_ArgTypes1...), _Alloc, _Rp(_ArgTypes...)>
2262 : public __base<_Rp(_ArgTypes...)>
2263{
2264 typedef _Rp1(^__block_type)(_ArgTypes1...);
2265 __block_type __f_;
2266
2267public:
2268 _LIBCPP_INLINE_VISIBILITY
2269 explicit __func(__block_type const& __f)
2270 : __f_(__f ? Block_copy(__f) : (__block_type)0)
2271 { }
2272
2273 // [TODO] add && to save on a retain
2274
2275 _LIBCPP_INLINE_VISIBILITY
2276 explicit __func(__block_type __f, const _Alloc& /* unused */)
2277 : __f_(__f ? Block_copy(__f) : (__block_type)0)
2278 { }
2279
2280 virtual __base<_Rp(_ArgTypes...)>* __clone() const {
2281 _LIBCPP_ASSERT(false,
2282 "Block pointers are just pointers, so they should always fit into "
2283 "std::function's small buffer optimization. This function should "
2284 "never be invoked.");
2285 return nullptr;
2286 }
2287
2288 virtual void __clone(__base<_Rp(_ArgTypes...)>* __p) const {
2289 ::new (__p) __func(__f_);
2290 }
2291
2292 virtual void destroy() _NOEXCEPT {
2293 if (__f_)
2294 Block_release(__f_);
2295 __f_ = 0;
2296 }
2297
2298 virtual void destroy_deallocate() _NOEXCEPT {
2299 _LIBCPP_ASSERT(false,
2300 "Block pointers are just pointers, so they should always fit into "
2301 "std::function's small buffer optimization. This function should "
2302 "never be invoked.");
2303 }
2304
2305 virtual _Rp operator()(_ArgTypes&& ... __arg) {
2306 return __invoke(__f_, _VSTD::forward<_ArgTypes>(__arg)...);
2307 }
2308
2309#ifndef _LIBCPP_NO_RTTI
2310 virtual const void* target(type_info const& __ti) const _NOEXCEPT {
2311 if (__ti == typeid(__func::__block_type))
2312 return &__f_;
2313 return (const void*)nullptr;
2314 }
2315
2316 virtual const std::type_info& target_type() const _NOEXCEPT {
2317 return typeid(__func::__block_type);
2318 }
2319#endif // _LIBCPP_NO_RTTI
2320};
2321
2322#endif // _LIBCPP_HAS_EXTENSION_BLOCKS && !_LIBCPP_HAS_OBJC_ARC
2323
22412324} // __function
22422325
22432326template<class _Rp, class ..._ArgTypes>
......@@ -2255,14 +2338,14 @@ class _LIBCPP_TEMPLATE_VIS function<_Rp(_ArgTypes...)>
22552338
22562339 template <class _Fp, bool = _And<
22572340 _IsNotSame<__uncvref_t<_Fp>, function>,
2258 __invokable<_Fp&, _ArgTypes...>
2341 __invokable<_Fp, _ArgTypes...>
22592342 >::value>
22602343 struct __callable;
22612344 template <class _Fp>
22622345 struct __callable<_Fp, true>
22632346 {
22642347 static const bool value = is_same<void, _Rp>::value ||
2265 is_convertible<typename __invoke_of<_Fp&, _ArgTypes...>::type,
2348 is_convertible<typename __invoke_of<_Fp, _ArgTypes...>::type,
22662349 _Rp>::value;
22672350 };
22682351 template <class _Fp>
......@@ -2272,7 +2355,7 @@ class _LIBCPP_TEMPLATE_VIS function<_Rp(_ArgTypes...)>
22722355 };
22732356
22742357 template <class _Fp>
2275 using _EnableIfCallable = typename enable_if<__callable<_Fp>::value>::type;
2358 using _EnableIfLValueCallable = typename enable_if<__callable<_Fp&>::value>::type;
22762359public:
22772360 typedef _Rp result_type;
22782361
......@@ -2283,7 +2366,7 @@ public:
22832366 function(nullptr_t) _NOEXCEPT {}
22842367 function(const function&);
22852368 function(function&&) _NOEXCEPT;
2286 template<class _Fp, class = _EnableIfCallable<_Fp>>
2369 template<class _Fp, class = _EnableIfLValueCallable<_Fp>>
22872370 function(_Fp);
22882371
22892372#if _LIBCPP_STD_VER <= 14
......@@ -2297,14 +2380,14 @@ public:
22972380 function(allocator_arg_t, const _Alloc&, const function&);
22982381 template<class _Alloc>
22992382 function(allocator_arg_t, const _Alloc&, function&&);
2300 template<class _Fp, class _Alloc, class = _EnableIfCallable<_Fp>>
2383 template<class _Fp, class _Alloc, class = _EnableIfLValueCallable<_Fp>>
23012384 function(allocator_arg_t, const _Alloc& __a, _Fp __f);
23022385#endif
23032386
23042387 function& operator=(const function&);
23052388 function& operator=(function&&) _NOEXCEPT;
23062389 function& operator=(nullptr_t) _NOEXCEPT;
2307 template<class _Fp, class = _EnableIfCallable<_Fp>>
2390 template<class _Fp, class = _EnableIfLValueCallable<typename decay<_Fp>::type>>
23082391 function& operator=(_Fp&&);
23092392
23102393 ~function();
......@@ -2967,14 +3050,14 @@ __search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
29673050 forward_iterator_tag, forward_iterator_tag)
29683051{
29693052 if (__first2 == __last2)
2970 return make_pair(__first1, __first1); // Everything matches an empty sequence
3053 return _VSTD::make_pair(__first1, __first1); // Everything matches an empty sequence
29713054 while (true)
29723055 {
29733056 // Find first element in sequence 1 that matchs *__first2, with a mininum of loop checks
29743057 while (true)
29753058 {
29763059 if (__first1 == __last1) // return __last1 if no element matches *__first2
2977 return make_pair(__last1, __last1);
3060 return _VSTD::make_pair(__last1, __last1);
29783061 if (__pred(*__first1, *__first2))
29793062 break;
29803063 ++__first1;
......@@ -2985,9 +3068,9 @@ __search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
29853068 while (true)
29863069 {
29873070 if (++__m2 == __last2) // If pattern exhausted, __first1 is the answer (works for 1 element pattern)
2988 return make_pair(__first1, __m1);
3071 return _VSTD::make_pair(__first1, __m1);
29893072 if (++__m1 == __last1) // Otherwise if source exhaused, pattern not found
2990 return make_pair(__last1, __last1);
3073 return _VSTD::make_pair(__last1, __last1);
29913074 if (!__pred(*__m1, *__m2)) // if there is a mismatch, restart with a new __first1
29923075 {
29933076 ++__first1;
......@@ -3009,10 +3092,10 @@ __search(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1,
30093092 // Take advantage of knowing source and pattern lengths. Stop short when source is smaller than pattern
30103093 const _D2 __len2 = __last2 - __first2;
30113094 if (__len2 == 0)
3012 return make_pair(__first1, __first1);
3095 return _VSTD::make_pair(__first1, __first1);
30133096 const _D1 __len1 = __last1 - __first1;
30143097 if (__len1 < __len2)
3015 return make_pair(__last1, __last1);
3098 return _VSTD::make_pair(__last1, __last1);
30163099 const _RandomAccessIterator1 __s = __last1 - (__len2 - 1); // Start of pattern match can't go beyond here
30173100
30183101 while (true)
......@@ -3020,7 +3103,7 @@ __search(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1,
30203103 while (true)
30213104 {
30223105 if (__first1 == __s)
3023 return make_pair(__last1, __last1);
3106 return _VSTD::make_pair(__last1, __last1);
30243107 if (__pred(*__first1, *__first2))
30253108 break;
30263109 ++__first1;
......@@ -3031,7 +3114,7 @@ __search(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1,
30313114 while (true)
30323115 {
30333116 if (++__m2 == __last2)
3034 return make_pair(__first1, __first1 + __len2);
3117 return _VSTD::make_pair(__first1, __first1 + __len2);
30353118 ++__m1; // no need to check range on __m1 because __s guarantees we have enough source
30363119 if (!__pred(*__m1, *__m2))
30373120 {
......@@ -3080,15 +3163,19 @@ using unwrap_ref_decay_t = typename unwrap_ref_decay<_Tp>::type;
30803163#endif // > C++17
30813164
30823165template <class _Container, class _Predicate>
3083inline void __libcpp_erase_if_container( _Container& __c, _Predicate __pred)
3084{
3085 for (typename _Container::iterator __iter = __c.begin(), __last = __c.end(); __iter != __last;)
3086 {
3087 if (__pred(*__iter))
3088 __iter = __c.erase(__iter);
3089 else
3090 ++__iter;
3091 }
3166inline typename _Container::size_type
3167__libcpp_erase_if_container(_Container& __c, _Predicate __pred) {
3168 typename _Container::size_type __old_size = __c.size();
3169
3170 const typename _Container::iterator __last = __c.end();
3171 for (typename _Container::iterator __iter = __c.begin(); __iter != __last;) {
3172 if (__pred(*__iter))
3173 __iter = __c.erase(__iter);
3174 else
3175 ++__iter;
3176 }
3177
3178 return __old_size - __c.size();
30923179}
30933180
30943181_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/future+1
......@@ -506,6 +506,7 @@ public:
506506 _LIBCPP_INLINE_VISIBILITY
507507 const error_code& code() const _NOEXCEPT {return __ec_;}
508508
509 future_error(const future_error&) _NOEXCEPT = default;
509510 virtual ~future_error() _NOEXCEPT;
510511};
511512
lib/libcxx/include/ios+26-25
......@@ -431,7 +431,8 @@ class _LIBCPP_EXCEPTION_ABI ios_base::failure
431431public:
432432 explicit failure(const string& __msg, const error_code& __ec = io_errc::stream);
433433 explicit failure(const char* __msg, const error_code& __ec = io_errc::stream);
434 virtual ~failure() throw();
434 failure(const failure&) _NOEXCEPT = default;
435 virtual ~failure() _NOEXCEPT;
435436};
436437
437438_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
......@@ -842,7 +843,7 @@ basic_ios<_CharT, _Traits>::set_rdbuf(basic_streambuf<char_type, traits_type>* _
842843 ios_base::set_rdbuf(__sb);
843844}
844845
845inline _LIBCPP_INLINE_VISIBILITY
846inline
846847ios_base&
847848boolalpha(ios_base& __str)
848849{
......@@ -850,7 +851,7 @@ boolalpha(ios_base& __str)
850851 return __str;
851852}
852853
853inline _LIBCPP_INLINE_VISIBILITY
854inline
854855ios_base&
855856noboolalpha(ios_base& __str)
856857{
......@@ -858,7 +859,7 @@ noboolalpha(ios_base& __str)
858859 return __str;
859860}
860861
861inline _LIBCPP_INLINE_VISIBILITY
862inline
862863ios_base&
863864showbase(ios_base& __str)
864865{
......@@ -866,7 +867,7 @@ showbase(ios_base& __str)
866867 return __str;
867868}
868869
869inline _LIBCPP_INLINE_VISIBILITY
870inline
870871ios_base&
871872noshowbase(ios_base& __str)
872873{
......@@ -874,7 +875,7 @@ noshowbase(ios_base& __str)
874875 return __str;
875876}
876877
877inline _LIBCPP_INLINE_VISIBILITY
878inline
878879ios_base&
879880showpoint(ios_base& __str)
880881{
......@@ -882,7 +883,7 @@ showpoint(ios_base& __str)
882883 return __str;
883884}
884885
885inline _LIBCPP_INLINE_VISIBILITY
886inline
886887ios_base&
887888noshowpoint(ios_base& __str)
888889{
......@@ -890,7 +891,7 @@ noshowpoint(ios_base& __str)
890891 return __str;
891892}
892893
893inline _LIBCPP_INLINE_VISIBILITY
894inline
894895ios_base&
895896showpos(ios_base& __str)
896897{
......@@ -898,7 +899,7 @@ showpos(ios_base& __str)
898899 return __str;
899900}
900901
901inline _LIBCPP_INLINE_VISIBILITY
902inline
902903ios_base&
903904noshowpos(ios_base& __str)
904905{
......@@ -906,7 +907,7 @@ noshowpos(ios_base& __str)
906907 return __str;
907908}
908909
909inline _LIBCPP_INLINE_VISIBILITY
910inline
910911ios_base&
911912skipws(ios_base& __str)
912913{
......@@ -914,7 +915,7 @@ skipws(ios_base& __str)
914915 return __str;
915916}
916917
917inline _LIBCPP_INLINE_VISIBILITY
918inline
918919ios_base&
919920noskipws(ios_base& __str)
920921{
......@@ -922,7 +923,7 @@ noskipws(ios_base& __str)
922923 return __str;
923924}
924925
925inline _LIBCPP_INLINE_VISIBILITY
926inline
926927ios_base&
927928uppercase(ios_base& __str)
928929{
......@@ -930,7 +931,7 @@ uppercase(ios_base& __str)
930931 return __str;
931932}
932933
933inline _LIBCPP_INLINE_VISIBILITY
934inline
934935ios_base&
935936nouppercase(ios_base& __str)
936937{
......@@ -938,7 +939,7 @@ nouppercase(ios_base& __str)
938939 return __str;
939940}
940941
941inline _LIBCPP_INLINE_VISIBILITY
942inline
942943ios_base&
943944unitbuf(ios_base& __str)
944945{
......@@ -946,7 +947,7 @@ unitbuf(ios_base& __str)
946947 return __str;
947948}
948949
949inline _LIBCPP_INLINE_VISIBILITY
950inline
950951ios_base&
951952nounitbuf(ios_base& __str)
952953{
......@@ -954,7 +955,7 @@ nounitbuf(ios_base& __str)
954955 return __str;
955956}
956957
957inline _LIBCPP_INLINE_VISIBILITY
958inline
958959ios_base&
959960internal(ios_base& __str)
960961{
......@@ -962,7 +963,7 @@ internal(ios_base& __str)
962963 return __str;
963964}
964965
965inline _LIBCPP_INLINE_VISIBILITY
966inline
966967ios_base&
967968left(ios_base& __str)
968969{
......@@ -970,7 +971,7 @@ left(ios_base& __str)
970971 return __str;
971972}
972973
973inline _LIBCPP_INLINE_VISIBILITY
974inline
974975ios_base&
975976right(ios_base& __str)
976977{
......@@ -978,7 +979,7 @@ right(ios_base& __str)
978979 return __str;
979980}
980981
981inline _LIBCPP_INLINE_VISIBILITY
982inline
982983ios_base&
983984dec(ios_base& __str)
984985{
......@@ -986,7 +987,7 @@ dec(ios_base& __str)
986987 return __str;
987988}
988989
989inline _LIBCPP_INLINE_VISIBILITY
990inline
990991ios_base&
991992hex(ios_base& __str)
992993{
......@@ -994,7 +995,7 @@ hex(ios_base& __str)
994995 return __str;
995996}
996997
997inline _LIBCPP_INLINE_VISIBILITY
998inline
998999ios_base&
9991000oct(ios_base& __str)
10001001{
......@@ -1002,7 +1003,7 @@ oct(ios_base& __str)
10021003 return __str;
10031004}
10041005
1005inline _LIBCPP_INLINE_VISIBILITY
1006inline
10061007ios_base&
10071008fixed(ios_base& __str)
10081009{
......@@ -1010,7 +1011,7 @@ fixed(ios_base& __str)
10101011 return __str;
10111012}
10121013
1013inline _LIBCPP_INLINE_VISIBILITY
1014inline
10141015ios_base&
10151016scientific(ios_base& __str)
10161017{
......@@ -1018,7 +1019,7 @@ scientific(ios_base& __str)
10181019 return __str;
10191020}
10201021
1021inline _LIBCPP_INLINE_VISIBILITY
1022inline
10221023ios_base&
10231024hexfloat(ios_base& __str)
10241025{
......@@ -1026,7 +1027,7 @@ hexfloat(ios_base& __str)
10261027 return __str;
10271028}
10281029
1029inline _LIBCPP_INLINE_VISIBILITY
1030inline
10301031ios_base&
10311032defaultfloat(ios_base& __str)
10321033{
lib/libcxx/include/iterator+10-11
......@@ -54,10 +54,8 @@ struct bidirectional_iterator_tag : public forward_iterator_tag {};
5454struct random_access_iterator_tag : public bidirectional_iterator_tag {};
5555
5656// 27.4.3, iterator operations
57// extension: second argument not conforming to C++03
58template <class InputIterator> // constexpr in C++17
59 constexpr void advance(InputIterator& i,
60 typename iterator_traits<InputIterator>::difference_type n);
57template <class InputIterator, class Distance> // constexpr in C++17
58 constexpr void advance(InputIterator& i, Distance n);
6159
6260template <class InputIterator> // constexpr in C++17
6361 constexpr typename iterator_traits<InputIterator>::difference_type
......@@ -663,13 +661,14 @@ void __advance(_RandIter& __i,
663661 __i += __n;
664662}
665663
666template <class _InputIter>
664template <class _InputIter, class _Distance>
667665inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
668void advance(_InputIter& __i,
669 typename iterator_traits<_InputIter>::difference_type __n)
666void advance(_InputIter& __i, _Distance __orig_n)
670667{
671 _LIBCPP_ASSERT(__n >= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
672 "Attempt to advance(it, -n) on a non-bidi iterator");
668 _LIBCPP_ASSERT(__orig_n >= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
669 "Attempt to advance(it, n) with negative n on a non-bidirectional iterator");
670 typedef decltype(__convert_to_integral(__orig_n)) _IntegralSize;
671 _IntegralSize __n = __orig_n;
673672 __advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category());
674673}
675674
......@@ -711,7 +710,7 @@ next(_InputIter __x,
711710 typename iterator_traits<_InputIter>::difference_type __n = 1)
712711{
713712 _LIBCPP_ASSERT(__n >= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
714 "Attempt to next(it, -n) on a non-bidi iterator");
713 "Attempt to next(it, n) with negative n on a non-bidirectional iterator");
715714
716715 _VSTD::advance(__x, __n);
717716 return __x;
......@@ -728,7 +727,7 @@ prev(_InputIter __x,
728727 typename iterator_traits<_InputIter>::difference_type __n = 1)
729728{
730729 _LIBCPP_ASSERT(__n <= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
731 "Attempt to prev(it, +n) on a non-bidi iterator");
730 "Attempt to prev(it, n) with a positive n on a non-bidirectional iterator");
732731 _VSTD::advance(__x, -__n);
733732 return __x;
734733}
lib/libcxx/include/latch created+104
......@@ -0,0 +1,104 @@
1// -*- C++ -*-
2//===--------------------------- latch -----------------------------------===//
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_LATCH
11#define _LIBCPP_LATCH
12
13/*
14 latch synopsis
15
16namespace std
17{
18
19 class latch
20 {
21 public:
22 constexpr explicit latch(ptrdiff_t __expected);
23 ~latch();
24
25 latch(const latch&) = delete;
26 latch& operator=(const latch&) = delete;
27
28 void count_down(ptrdiff_t __update = 1);
29 bool try_wait() const noexcept;
30 void wait() const;
31 void arrive_and_wait(ptrdiff_t __update = 1);
32
33 private:
34 ptrdiff_t __counter; // exposition only
35 };
36
37}
38
39*/
40
41#include <__config>
42#include <atomic>
43
44#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
45#pragma GCC system_header
46#endif
47
48#ifdef _LIBCPP_HAS_NO_THREADS
49# error <latch> is not supported on this single threaded system
50#endif
51
52#if _LIBCPP_STD_VER >= 14
53
54_LIBCPP_BEGIN_NAMESPACE_STD
55
56class latch
57{
58 __atomic_base<ptrdiff_t> __a;
59
60public:
61 static constexpr ptrdiff_t max() noexcept {
62 return numeric_limits<ptrdiff_t>::max();
63 }
64
65 inline _LIBCPP_INLINE_VISIBILITY
66 constexpr explicit latch(ptrdiff_t __expected) : __a(__expected) { }
67
68 ~latch() = default;
69 latch(const latch&) = delete;
70 latch& operator=(const latch&) = delete;
71
72 inline _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
73 void count_down(ptrdiff_t __update = 1)
74 {
75 auto const __old = __a.fetch_sub(__update, memory_order_release);
76 if(__old == __update)
77 __a.notify_all();
78 }
79 inline _LIBCPP_INLINE_VISIBILITY
80 bool try_wait() const noexcept
81 {
82 return 0 == __a.load(memory_order_acquire);
83 }
84 inline _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
85 void wait() const
86 {
87 auto const __test_fn = [=]() -> bool {
88 return try_wait();
89 };
90 __cxx_atomic_wait(&__a.__a_, __test_fn);
91 }
92 inline _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
93 void arrive_and_wait(ptrdiff_t __update = 1)
94 {
95 count_down(__update);
96 wait();
97 }
98};
99
100_LIBCPP_END_NAMESPACE_STD
101
102#endif // _LIBCPP_STD_VER >= 14
103
104#endif //_LIBCPP_LATCH
lib/libcxx/include/list+12-8
......@@ -170,9 +170,11 @@ template <class T, class Alloc>
170170 noexcept(noexcept(x.swap(y)));
171171
172172template <class T, class Allocator, class U>
173 void erase(list<T, Allocator>& c, const U& value); // C++20
173 typename list<T, Allocator>::size_type
174 erase(list<T, Allocator>& c, const U& value); // C++20
174175template <class T, class Allocator, class Predicate>
175 void erase_if(list<T, Allocator>& c, Predicate pred); // C++20
176 typename list<T, Allocator>::size_type
177 erase_if(list<T, Allocator>& c, Predicate pred); // C++20
176178
177179} // std
178180
......@@ -2471,14 +2473,16 @@ swap(list<_Tp, _Alloc>& __x, list<_Tp, _Alloc>& __y)
24712473
24722474#if _LIBCPP_STD_VER > 17
24732475template <class _Tp, class _Allocator, class _Predicate>
2474inline _LIBCPP_INLINE_VISIBILITY
2475void erase_if(list<_Tp, _Allocator>& __c, _Predicate __pred)
2476{ __c.remove_if(__pred); }
2476inline _LIBCPP_INLINE_VISIBILITY typename list<_Tp, _Allocator>::size_type
2477erase_if(list<_Tp, _Allocator>& __c, _Predicate __pred) {
2478 return __c.remove_if(__pred);
2479}
24772480
24782481template <class _Tp, class _Allocator, class _Up>
2479inline _LIBCPP_INLINE_VISIBILITY
2480void erase(list<_Tp, _Allocator>& __c, const _Up& __v)
2481{ _VSTD::erase_if(__c, [&](auto& __elem) { return __elem == __v; }); }
2482inline _LIBCPP_INLINE_VISIBILITY typename list<_Tp, _Allocator>::size_type
2483erase(list<_Tp, _Allocator>& __c, const _Up& __v) {
2484 return _VSTD::erase_if(__c, [&](auto& __elem) { return __elem == __v; });
2485}
24822486#endif
24832487
24842488_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/map+17-8
......@@ -254,7 +254,8 @@ swap(map<Key, T, Compare, Allocator>& x, map<Key, T, Compare, Allocator>& y)
254254 noexcept(noexcept(x.swap(y)));
255255
256256template <class Key, class T, class Compare, class Allocator, class Predicate>
257 void erase_if(map<Key, T, Compare, Allocator>& c, Predicate pred); // C++20
257typename map<Key, T, Compare, Allocator>::size_type
258erase_if(map<Key, T, Compare, Allocator>& c, Predicate pred); // C++20
258259
259260
260261template <class Key, class T, class Compare = less<Key>,
......@@ -469,7 +470,8 @@ swap(multimap<Key, T, Compare, Allocator>& x,
469470 noexcept(noexcept(x.swap(y)));
470471
471472template <class Key, class T, class Compare, class Allocator, class Predicate>
472 void erase_if(multimap<Key, T, Compare, Allocator>& c, Predicate pred); // C++20
473typename multimap<Key, T, Compare, Allocator>::size_type
474erase_if(multimap<Key, T, Compare, Allocator>& c, Predicate pred); // C++20
473475
474476} // std
475477
......@@ -1653,10 +1655,13 @@ swap(map<_Key, _Tp, _Compare, _Allocator>& __x,
16531655}
16541656
16551657#if _LIBCPP_STD_VER > 17
1656template <class _Key, class _Tp, class _Compare, class _Allocator, class _Predicate>
1658template <class _Key, class _Tp, class _Compare, class _Allocator,
1659 class _Predicate>
16571660inline _LIBCPP_INLINE_VISIBILITY
1658void erase_if(map<_Key, _Tp, _Compare, _Allocator>& __c, _Predicate __pred)
1659{ __libcpp_erase_if_container(__c, __pred); }
1661 typename map<_Key, _Tp, _Compare, _Allocator>::size_type
1662 erase_if(map<_Key, _Tp, _Compare, _Allocator>& __c, _Predicate __pred) {
1663 return __libcpp_erase_if_container(__c, __pred);
1664}
16601665#endif
16611666
16621667
......@@ -2235,10 +2240,14 @@ swap(multimap<_Key, _Tp, _Compare, _Allocator>& __x,
22352240}
22362241
22372242#if _LIBCPP_STD_VER > 17
2238template <class _Key, class _Tp, class _Compare, class _Allocator, class _Predicate>
2243template <class _Key, class _Tp, class _Compare, class _Allocator,
2244 class _Predicate>
22392245inline _LIBCPP_INLINE_VISIBILITY
2240void erase_if(multimap<_Key, _Tp, _Compare, _Allocator>& __c, _Predicate __pred)
2241{ __libcpp_erase_if_container(__c, __pred); }
2246 typename multimap<_Key, _Tp, _Compare, _Allocator>::size_type
2247 erase_if(multimap<_Key, _Tp, _Compare, _Allocator>& __c,
2248 _Predicate __pred) {
2249 return __libcpp_erase_if_container(__c, __pred);
2250}
22422251#endif
22432252
22442253_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/math.h+5-56
......@@ -297,9 +297,6 @@ long double truncl(long double x);
297297#pragma GCC system_header
298298#endif
299299
300#define _LIBCPP_STDLIB_INCLUDE_NEXT
301#include <stdlib.h>
302
303300#include_next <math.h>
304301
305302#ifdef __cplusplus
......@@ -308,6 +305,7 @@ long double truncl(long double x);
308305// back to C++ linkage before including these C++ headers.
309306extern "C++" {
310307
308#include <stdlib.h>
311309#include <type_traits>
312310#include <limits>
313311
......@@ -760,61 +758,12 @@ isunordered(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
760758#endif // isunordered
761759
762760// abs
763
764#undef abs
765#undef labs
766#ifndef _LIBCPP_HAS_NO_LONG_LONG
767#undef llabs
768#endif
769
770// MSVCRT already has the correct prototype in <stdlib.h> if __cplusplus is defined
771#if !defined(_LIBCPP_MSVCRT) && !defined(__sun__) && !defined(_AIX)
772inline _LIBCPP_INLINE_VISIBILITY long abs(long __x) _NOEXCEPT {
773 return ::labs(__x);
774}
775#ifndef _LIBCPP_HAS_NO_LONG_LONG
776inline _LIBCPP_INLINE_VISIBILITY long long abs(long long __x) _NOEXCEPT {
777 return ::llabs(__x);
778}
779#endif // _LIBCPP_HAS_NO_LONG_LONG
780#endif // !defined(_LIBCPP_MSVCRT) && !defined(__sun__) && !defined(_AIX)
781
782
783#if !(defined(_AIX) || defined(__sun__))
784inline _LIBCPP_INLINE_VISIBILITY float abs(float __lcpp_x) _NOEXCEPT {
785 return ::fabsf(__lcpp_x);
786}
787
788inline _LIBCPP_INLINE_VISIBILITY double abs(double __lcpp_x) _NOEXCEPT {
789 return ::fabs(__lcpp_x);
790}
791
792inline _LIBCPP_INLINE_VISIBILITY long double
793abs(long double __lcpp_x) _NOEXCEPT {
794 return ::fabsl(__lcpp_x);
795}
796#endif // !(defined(_AIX) || defined(__sun__))
761//
762// handled in stdlib.h
797763
798764// div
799
800#undef div
801#undef ldiv
802#ifndef _LIBCPP_HAS_NO_LONG_LONG
803#undef lldiv
804#endif
805
806// MSVCRT already has the correct prototype in <stdlib.h> if __cplusplus is defined
807#if !defined(_LIBCPP_MSVCRT) && !defined(__sun__) && !defined(_AIX)
808inline _LIBCPP_INLINE_VISIBILITY ldiv_t div(long __x, long __y) _NOEXCEPT {
809 return ::ldiv(__x, __y);
810}
811#ifndef _LIBCPP_HAS_NO_LONG_LONG
812inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x,
813 long long __y) _NOEXCEPT {
814 return ::lldiv(__x, __y);
815}
816#endif // _LIBCPP_HAS_NO_LONG_LONG
817#endif // _LIBCPP_MSVCRT / __sun__ / _AIX
765//
766// handled in stdlib.h
818767
819768// acos
820769
lib/libcxx/include/memory+290-382
......@@ -80,7 +80,7 @@ struct allocator_traits
8080 typedef Alloc::is_always_equal
8181 | is_empty is_always_equal;
8282
83 template <class T> using rebind_alloc = Alloc::rebind<U>::other | Alloc<T, Args...>;
83 template <class T> using rebind_alloc = Alloc::rebind<T>::other | Alloc<T, Args...>;
8484 template <class T> using rebind_traits = allocator_traits<rebind_alloc<T>>;
8585
8686 static pointer allocate(allocator_type& a, size_type n); // [[nodiscard]] in C++20
......@@ -101,7 +101,7 @@ struct allocator_traits
101101};
102102
103103template <>
104class allocator<void>
104class allocator<void> // deprecated in C++17, removed in C++20
105105{
106106public:
107107 typedef void* pointer;
......@@ -115,30 +115,37 @@ template <class T>
115115class allocator
116116{
117117public:
118 typedef size_t size_type;
119 typedef ptrdiff_t difference_type;
120 typedef T* pointer;
121 typedef const T* const_pointer;
122 typedef typename add_lvalue_reference<T>::type reference;
123 typedef typename add_lvalue_reference<const T>::type const_reference;
124 typedef T value_type;
118 typedef size_t size_type; // deprecated in C++17, removed in C++20
119 typedef ptrdiff_t difference_type; // deprecated in C++17, removed in C++20
120 typedef T* pointer; // deprecated in C++17, removed in C++20
121 typedef const T* const_pointer; // deprecated in C++17, removed in C++20
122 typedef typename add_lvalue_reference<T>::type
123 reference; // deprecated in C++17, removed in C++20
124 typedef typename add_lvalue_reference<const T>::type
125 const_reference; // deprecated in C++17, removed in C++20
125126
126 template <class U> struct rebind {typedef allocator<U> other;};
127 typedef T value_type;
128
129 template <class U> struct rebind {typedef allocator<U> other;}; // deprecated in C++17, removed in C++20
130
131 typedef true_type propagate_on_container_move_assignment;
132 typedef true_type is_always_equal;
127133
128134 constexpr allocator() noexcept; // constexpr in C++20
129135 constexpr allocator(const allocator&) noexcept; // constexpr in C++20
130136 template <class U>
131137 constexpr allocator(const allocator<U>&) noexcept; // constexpr in C++20
132138 ~allocator();
133 pointer address(reference x) const noexcept;
134 const_pointer address(const_reference x) const noexcept;
135 pointer allocate(size_type, allocator<void>::const_pointer hint = 0);
136 void deallocate(pointer p, size_type n) noexcept;
137 size_type max_size() const noexcept;
139 pointer address(reference x) const noexcept; // deprecated in C++17, removed in C++20
140 const_pointer address(const_reference x) const noexcept; // deprecated in C++17, removed in C++20
141 T* allocate(size_t n, const void* hint); // deprecated in C++17, removed in C++20
142 T* allocate(size_t n);
143 void deallocate(T* p, size_t n) noexcept;
144 size_type max_size() const noexcept; // deprecated in C++17, removed in C++20
138145 template<class U, class... Args>
139 void construct(U* p, Args&&... args);
146 void construct(U* p, Args&&... args); // deprecated in C++17, removed in C++20
140147 template <class U>
141 void destroy(U* p);
148 void destroy(U* p); // deprecated in C++17, removed in C++20
142149};
143150
144151template <class T, class U>
......@@ -443,6 +450,11 @@ public:
443450 template<class U> bool owner_before(weak_ptr<U> const& b) const noexcept;
444451};
445452
453template<class T>
454shared_ptr(weak_ptr<T>) -> shared_ptr<T>;
455template<class T, class D>
456shared_ptr(unique_ptr<T, D>) -> shared_ptr<T>;
457
446458// shared_ptr comparisons:
447459template<class T, class U>
448460 bool operator==(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
......@@ -541,6 +553,9 @@ public:
541553 template<class U> bool owner_before(weak_ptr<U> const& b) const noexcept;
542554};
543555
556template<class T>
557weak_ptr(shared_ptr<T>) -> weak_ptr<T>;
558
544559// weak_ptr specialized algorithms:
545560template<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b) noexcept;
546561
......@@ -705,8 +720,9 @@ _ValueType __libcpp_acquire_load(_ValueType const* __value) {
705720
706721template <class _Tp> class allocator;
707722
723#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS)
708724template <>
709class _LIBCPP_TEMPLATE_VIS allocator<void>
725class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 allocator<void>
710726{
711727public:
712728 typedef void* pointer;
......@@ -717,7 +733,7 @@ public:
717733};
718734
719735template <>
720class _LIBCPP_TEMPLATE_VIS allocator<const void>
736class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 allocator<const void>
721737{
722738public:
723739 typedef const void* pointer;
......@@ -726,6 +742,7 @@ public:
726742
727743 template <class _Up> struct rebind {typedef allocator<_Up> other;};
728744};
745#endif
729746
730747// pointer_traits
731748
......@@ -838,7 +855,9 @@ struct __has_rebind
838855private:
839856 struct __two {char __lx; char __lxx;};
840857 template <class _Xp> static __two __test(...);
858 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
841859 template <class _Xp> static char __test(typename _Xp::template rebind<_Up>* = 0);
860 _LIBCPP_SUPPRESS_DEPRECATED_POP
842861public:
843862 static const bool value = sizeof(__test<_Tp>(0)) == 1;
844863};
......@@ -1266,7 +1285,9 @@ struct __has_rebind_other
12661285private:
12671286 struct __two {char __lx; char __lxx;};
12681287 template <class _Xp> static __two __test(...);
1288 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
12691289 template <class _Xp> static char __test(typename _Xp::template rebind<_Up>::other* = 0);
1290 _LIBCPP_SUPPRESS_DEPRECATED_POP
12701291public:
12711292 static const bool value = sizeof(__test<_Tp>(0)) == 1;
12721293};
......@@ -1280,15 +1301,17 @@ struct __has_rebind_other<_Tp, _Up, false>
12801301template <class _Tp, class _Up, bool = __has_rebind_other<_Tp, _Up>::value>
12811302struct __allocator_traits_rebind
12821303{
1304 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
12831305 typedef _LIBCPP_NODEBUG_TYPE typename _Tp::template rebind<_Up>::other type;
1306 _LIBCPP_SUPPRESS_DEPRECATED_POP
12841307};
12851308
1286#ifndef _LIBCPP_HAS_NO_VARIADICS
1287
12881309template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
12891310struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, true>
12901311{
1312 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
12911313 typedef _LIBCPP_NODEBUG_TYPE typename _Alloc<_Tp, _Args...>::template rebind<_Up>::other type;
1314 _LIBCPP_SUPPRESS_DEPRECATED_POP
12921315};
12931316
12941317template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
......@@ -1297,68 +1320,14 @@ struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, false>
12971320 typedef _LIBCPP_NODEBUG_TYPE _Alloc<_Up, _Args...> type;
12981321};
12991322
1300#else // _LIBCPP_HAS_NO_VARIADICS
1301
1302template <template <class> class _Alloc, class _Tp, class _Up>
1303struct __allocator_traits_rebind<_Alloc<_Tp>, _Up, true>
1304{
1305 typedef typename _Alloc<_Tp>::template rebind<_Up>::other type;
1306};
1307
1308template <template <class> class _Alloc, class _Tp, class _Up>
1309struct __allocator_traits_rebind<_Alloc<_Tp>, _Up, false>
1310{
1311 typedef _Alloc<_Up> type;
1312};
1313
1314template <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>
1315struct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, true>
1316{
1317 typedef typename _Alloc<_Tp, _A0>::template rebind<_Up>::other type;
1318};
1319
1320template <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>
1321struct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, false>
1322{
1323 typedef _Alloc<_Up, _A0> type;
1324};
1325
1326template <template <class, class, class> class _Alloc, class _Tp, class _A0,
1327 class _A1, class _Up>
1328struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, true>
1329{
1330 typedef typename _Alloc<_Tp, _A0, _A1>::template rebind<_Up>::other type;
1331};
1332
1333template <template <class, class, class> class _Alloc, class _Tp, class _A0,
1334 class _A1, class _Up>
1335struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, false>
1336{
1337 typedef _Alloc<_Up, _A0, _A1> type;
1338};
1339
1340template <template <class, class, class, class> class _Alloc, class _Tp, class _A0,
1341 class _A1, class _A2, class _Up>
1342struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, true>
1343{
1344 typedef typename _Alloc<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type;
1345};
1346
1347template <template <class, class, class, class> class _Alloc, class _Tp, class _A0,
1348 class _A1, class _A2, class _Up>
1349struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, false>
1350{
1351 typedef _Alloc<_Up, _A0, _A1, _A2> type;
1352};
1353
1354#endif // _LIBCPP_HAS_NO_VARIADICS
1355
13561323#ifndef _LIBCPP_CXX03_LANG
13571324
1325_LIBCPP_SUPPRESS_DEPRECATED_PUSH
13581326template <class _Alloc, class _SizeType, class _ConstVoidPtr>
13591327auto
13601328__has_allocate_hint_test(_Alloc&& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
13611329 -> decltype((void)__a.allocate(__sz, __p), true_type());
1330_LIBCPP_SUPPRESS_DEPRECATED_POP
13621331
13631332template <class _Alloc, class _SizeType, class _ConstVoidPtr>
13641333auto
......@@ -1367,12 +1336,9 @@ __has_allocate_hint_test(const _Alloc& __a, _SizeType&& __sz, _ConstVoidPtr&& __
13671336
13681337template <class _Alloc, class _SizeType, class _ConstVoidPtr>
13691338struct __has_allocate_hint
1370 : integral_constant<bool,
1371 is_same<
1372 decltype(_VSTD::__has_allocate_hint_test(declval<_Alloc>(),
1373 declval<_SizeType>(),
1374 declval<_ConstVoidPtr>())),
1375 true_type>::value>
1339 : decltype(_VSTD::__has_allocate_hint_test(declval<_Alloc>(),
1340 declval<_SizeType>(),
1341 declval<_ConstVoidPtr>()))
13761342{
13771343};
13781344
......@@ -1386,33 +1352,26 @@ struct __has_allocate_hint
13861352
13871353#endif // _LIBCPP_CXX03_LANG
13881354
1389#if !defined(_LIBCPP_CXX03_LANG)
1355_LIBCPP_SUPPRESS_DEPRECATED_PUSH
1356template <class _Alloc, class ..._Args,
1357 class = decltype(_VSTD::declval<_Alloc>().construct(_VSTD::declval<_Args>()...))>
1358static true_type __test_has_construct(int);
1359_LIBCPP_SUPPRESS_DEPRECATED_POP
13901360
1391template <class _Alloc, class _Tp, class ..._Args>
1392decltype(_VSTD::declval<_Alloc>().construct(_VSTD::declval<_Tp*>(),
1393 _VSTD::declval<_Args>()...),
1394 true_type())
1395__has_construct_test(_Alloc&& __a, _Tp* __p, _Args&& ...__args);
1396
1397template <class _Alloc, class _Pointer, class ..._Args>
1398false_type
1399__has_construct_test(const _Alloc& __a, _Pointer&& __p, _Args&& ...__args);
1400
1401template <class _Alloc, class _Pointer, class ..._Args>
1402struct __has_construct
1403 : integral_constant<bool,
1404 is_same<
1405 decltype(_VSTD::__has_construct_test(declval<_Alloc>(),
1406 declval<_Pointer>(),
1407 declval<_Args>()...)),
1408 true_type>::value>
1409{
1410};
1361template <class _Alloc, class...>
1362static false_type __test_has_construct(...);
1363
1364template <class _Alloc, class ..._Args>
1365struct __has_construct : decltype(__test_has_construct<_Alloc, _Args...>(0)) {};
1366
1367#if !defined(_LIBCPP_CXX03_LANG)
14111368
1369_LIBCPP_SUPPRESS_DEPRECATED_PUSH
14121370template <class _Alloc, class _Pointer>
14131371auto
14141372__has_destroy_test(_Alloc&& __a, _Pointer&& __p)
14151373 -> decltype(__a.destroy(__p), true_type());
1374_LIBCPP_SUPPRESS_DEPRECATED_POP
14161375
14171376template <class _Alloc, class _Pointer>
14181377auto
......@@ -1421,18 +1380,17 @@ __has_destroy_test(const _Alloc& __a, _Pointer&& __p)
14211380
14221381template <class _Alloc, class _Pointer>
14231382struct __has_destroy
1424 : integral_constant<bool,
1425 is_same<
1426 decltype(_VSTD::__has_destroy_test(declval<_Alloc>(),
1427 declval<_Pointer>())),
1428 true_type>::value>
1383 : decltype(_VSTD::__has_destroy_test(declval<_Alloc>(),
1384 declval<_Pointer>()))
14291385{
14301386};
14311387
1388_LIBCPP_SUPPRESS_DEPRECATED_PUSH
14321389template <class _Alloc>
14331390auto
14341391__has_max_size_test(_Alloc&& __a)
14351392 -> decltype(__a.max_size(), true_type());
1393_LIBCPP_SUPPRESS_DEPRECATED_POP
14361394
14371395template <class _Alloc>
14381396auto
......@@ -1441,10 +1399,7 @@ __has_max_size_test(const volatile _Alloc& __a)
14411399
14421400template <class _Alloc>
14431401struct __has_max_size
1444 : integral_constant<bool,
1445 is_same<
1446 decltype(_VSTD::__has_max_size_test(declval<_Alloc&>())),
1447 true_type>::value>
1402 : decltype(_VSTD::__has_max_size_test(declval<_Alloc&>()))
14481403{
14491404};
14501405
......@@ -1460,23 +1415,12 @@ __has_select_on_container_copy_construction_test(const volatile _Alloc& __a)
14601415
14611416template <class _Alloc>
14621417struct __has_select_on_container_copy_construction
1463 : integral_constant<bool,
1464 is_same<
1465 decltype(_VSTD::__has_select_on_container_copy_construction_test(declval<_Alloc&>())),
1466 true_type>::value>
1418 : decltype(_VSTD::__has_select_on_container_copy_construction_test(declval<_Alloc&>()))
14671419{
14681420};
14691421
14701422#else // _LIBCPP_CXX03_LANG
14711423
1472template <class _Alloc, class _Pointer, class _Tp, class = void>
1473struct __has_construct : std::false_type {};
1474
1475template <class _Alloc, class _Pointer, class _Tp>
1476struct __has_construct<_Alloc, _Pointer, _Tp, typename __void_t<
1477 decltype(_VSTD::declval<_Alloc>().construct(_VSTD::declval<_Pointer>(), _VSTD::declval<_Tp>()))
1478>::type> : std::true_type {};
1479
14801424template <class _Alloc, class _Pointer, class = void>
14811425struct __has_destroy : false_type {};
14821426
......@@ -1588,41 +1532,11 @@ struct _LIBCPP_TEMPLATE_VIS allocator_traits
15881532 static void deallocate(allocator_type& __a, pointer __p, size_type __n) _NOEXCEPT
15891533 {__a.deallocate(__p, __n);}
15901534
1591#ifndef _LIBCPP_HAS_NO_VARIADICS
15921535 template <class _Tp, class... _Args>
15931536 _LIBCPP_INLINE_VISIBILITY
15941537 static void construct(allocator_type& __a, _Tp* __p, _Args&&... __args)
15951538 {__construct(__has_construct<allocator_type, _Tp*, _Args...>(),
15961539 __a, __p, _VSTD::forward<_Args>(__args)...);}
1597#else // _LIBCPP_HAS_NO_VARIADICS
1598 template <class _Tp>
1599 _LIBCPP_INLINE_VISIBILITY
1600 static void construct(allocator_type&, _Tp* __p)
1601 {
1602 ::new ((void*)__p) _Tp();
1603 }
1604 template <class _Tp, class _A0>
1605 _LIBCPP_INLINE_VISIBILITY
1606 static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0)
1607 {
1608 __construct(__has_construct<allocator_type, _Tp*, const _A0&>(),
1609 __a, __p, __a0);
1610 }
1611 template <class _Tp, class _A0, class _A1>
1612 _LIBCPP_INLINE_VISIBILITY
1613 static void construct(allocator_type&, _Tp* __p, const _A0& __a0,
1614 const _A1& __a1)
1615 {
1616 ::new ((void*)__p) _Tp(__a0, __a1);
1617 }
1618 template <class _Tp, class _A0, class _A1, class _A2>
1619 _LIBCPP_INLINE_VISIBILITY
1620 static void construct(allocator_type&, _Tp* __p, const _A0& __a0,
1621 const _A1& __a1, const _A2& __a2)
1622 {
1623 ::new ((void*)__p) _Tp(__a0, __a1, __a2);
1624 }
1625#endif // _LIBCPP_HAS_NO_VARIADICS
16261540
16271541 template <class _Tp>
16281542 _LIBCPP_INLINE_VISIBILITY
......@@ -1695,7 +1609,7 @@ struct _LIBCPP_TEMPLATE_VIS allocator_traits
16951609 static
16961610 typename enable_if
16971611 <
1698 is_trivially_move_constructible<_DestTp>::value &&
1612 is_trivially_copy_constructible<_DestTp>::value &&
16991613 is_same<_RawSourceTp, _RawDestTp>::value &&
17001614 (__is_default_allocator<allocator_type>::value ||
17011615 !__has_construct<allocator_type, _DestTp*, _SourceTp&>::value),
......@@ -1755,42 +1669,40 @@ private:
17551669 _LIBCPP_INLINE_VISIBILITY
17561670 static pointer __allocate(allocator_type& __a, size_type __n,
17571671 const_void_pointer __hint, true_type)
1758 {return __a.allocate(__n, __hint);}
1672 {
1673 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
1674 return __a.allocate(__n, __hint);
1675 _LIBCPP_SUPPRESS_DEPRECATED_POP
1676 }
17591677 _LIBCPP_INLINE_VISIBILITY
17601678 static pointer __allocate(allocator_type& __a, size_type __n,
17611679 const_void_pointer, false_type)
17621680 {return __a.allocate(__n);}
17631681
1764#ifndef _LIBCPP_HAS_NO_VARIADICS
17651682 template <class _Tp, class... _Args>
17661683 _LIBCPP_INLINE_VISIBILITY
17671684 static void __construct(true_type, allocator_type& __a, _Tp* __p, _Args&&... __args)
1768 {__a.construct(__p, _VSTD::forward<_Args>(__args)...);}
1685 {
1686 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
1687 __a.construct(__p, _VSTD::forward<_Args>(__args)...);
1688 _LIBCPP_SUPPRESS_DEPRECATED_POP
1689 }
1690
17691691 template <class _Tp, class... _Args>
17701692 _LIBCPP_INLINE_VISIBILITY
17711693 static void __construct(false_type, allocator_type&, _Tp* __p, _Args&&... __args)
17721694 {
17731695 ::new ((void*)__p) _Tp(_VSTD::forward<_Args>(__args)...);
17741696 }
1775#else // _LIBCPP_HAS_NO_VARIADICS
1776 template <class _Tp, class _A0>
1777 _LIBCPP_INLINE_VISIBILITY
1778 static void __construct(true_type, allocator_type& __a, _Tp* __p,
1779 const _A0& __a0)
1780 {__a.construct(__p, __a0);}
1781 template <class _Tp, class _A0>
1782 _LIBCPP_INLINE_VISIBILITY
1783 static void __construct(false_type, allocator_type&, _Tp* __p,
1784 const _A0& __a0)
1785 {
1786 ::new ((void*)__p) _Tp(__a0);
1787 }
1788#endif // _LIBCPP_HAS_NO_VARIADICS
17891697
17901698 template <class _Tp>
17911699 _LIBCPP_INLINE_VISIBILITY
17921700 static void __destroy(true_type, allocator_type& __a, _Tp* __p)
1793 {__a.destroy(__p);}
1701 {
1702 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
1703 __a.destroy(__p);
1704 _LIBCPP_SUPPRESS_DEPRECATED_POP
1705 }
17941706 template <class _Tp>
17951707 _LIBCPP_INLINE_VISIBILITY
17961708 static void __destroy(false_type, allocator_type&, _Tp* __p)
......@@ -1800,7 +1712,12 @@ private:
18001712
18011713 _LIBCPP_INLINE_VISIBILITY
18021714 static size_type __max_size(true_type, const allocator_type& __a) _NOEXCEPT
1803 {return __a.max_size();}
1715 {
1716 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
1717 return __a.max_size();
1718 _LIBCPP_SUPPRESS_DEPRECATED_POP
1719 }
1720
18041721 _LIBCPP_INLINE_VISIBILITY
18051722 static size_type __max_size(false_type, const allocator_type&) _NOEXCEPT
18061723 {return numeric_limits<size_type>::max() / sizeof(value_type);}
......@@ -1831,19 +1748,22 @@ template <class _Tp>
18311748class _LIBCPP_TEMPLATE_VIS allocator
18321749{
18331750public:
1834 typedef size_t size_type;
1835 typedef ptrdiff_t difference_type;
1836 typedef _Tp* pointer;
1837 typedef const _Tp* const_pointer;
1838 typedef _Tp& reference;
1839 typedef const _Tp& const_reference;
1840 typedef _Tp value_type;
1751#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS)
1752 _LIBCPP_DEPRECATED_IN_CXX17 typedef size_t size_type;
1753 _LIBCPP_DEPRECATED_IN_CXX17 typedef ptrdiff_t difference_type;
1754 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp* pointer;
1755 _LIBCPP_DEPRECATED_IN_CXX17 typedef const _Tp* const_pointer;
1756 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp& reference;
1757 _LIBCPP_DEPRECATED_IN_CXX17 typedef const _Tp& const_reference;
1758
1759 template <class _Up> struct _LIBCPP_DEPRECATED_IN_CXX17 rebind {typedef allocator<_Up> other;};
1760#endif
1761
1762 typedef _Tp value_type;
18411763
18421764 typedef true_type propagate_on_container_move_assignment;
18431765 typedef true_type is_always_equal;
18441766
1845 template <class _Up> struct rebind {typedef allocator<_Up> other;};
1846
18471767 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
18481768 allocator() _NOEXCEPT {}
18491769
......@@ -1851,103 +1771,67 @@ public:
18511771 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
18521772 allocator(const allocator<_Up>&) _NOEXCEPT {}
18531773
1854 _LIBCPP_INLINE_VISIBILITY pointer address(reference __x) const _NOEXCEPT
1774#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS)
1775 _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_INLINE_VISIBILITY
1776 pointer address(reference __x) const _NOEXCEPT
18551777 {return _VSTD::addressof(__x);}
1856 _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
1778 _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_INLINE_VISIBILITY
1779 const_pointer address(const_reference __x) const _NOEXCEPT
18571780 {return _VSTD::addressof(__x);}
1858 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
1859 pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
1781#endif
1782
1783 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _Tp* allocate(size_t __n)
18601784 {
1861 if (__n > max_size())
1785 // TODO(mpark): Replace with `allocator_traits<allocator>::max_size(*this)`.
1786 if (__n > (size_t(~0) / sizeof(_Tp)))
18621787 __throw_length_error("allocator<T>::allocate(size_t n)"
18631788 " 'n' exceeds maximum supported size");
1864 return static_cast<pointer>(_VSTD::__libcpp_allocate(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)));
1789 return static_cast<_Tp*>(_VSTD::__libcpp_allocate(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)));
18651790 }
1866 _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type __n) _NOEXCEPT
1791
1792#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS)
1793 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_DEPRECATED_IN_CXX17
1794 _Tp* allocate(size_t __n, const void*) { return allocate(__n); }
1795#endif
1796
1797 _LIBCPP_INLINE_VISIBILITY void deallocate(_Tp* __p, size_t __n) _NOEXCEPT
18671798 {_VSTD::__libcpp_deallocate((void*)__p, __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp));}
1868 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1799
1800#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS)
1801 _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
18691802 {return size_type(~0) / sizeof(_Tp);}
1870#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1803
18711804 template <class _Up, class... _Args>
1872 _LIBCPP_INLINE_VISIBILITY
1805 _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_INLINE_VISIBILITY
18731806 void
18741807 construct(_Up* __p, _Args&&... __args)
18751808 {
18761809 ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
18771810 }
1878#else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1879 _LIBCPP_INLINE_VISIBILITY
1880 void
1881 construct(pointer __p)
1882 {
1883 ::new((void*)__p) _Tp();
1884 }
1885# if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1886
1887 template <class _A0>
1888 _LIBCPP_INLINE_VISIBILITY
1889 void
1890 construct(pointer __p, _A0& __a0)
1891 {
1892 ::new((void*)__p) _Tp(__a0);
1893 }
1894 template <class _A0>
1895 _LIBCPP_INLINE_VISIBILITY
1896 void
1897 construct(pointer __p, const _A0& __a0)
1898 {
1899 ::new((void*)__p) _Tp(__a0);
1900 }
1901# endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1902 template <class _A0, class _A1>
1903 _LIBCPP_INLINE_VISIBILITY
1904 void
1905 construct(pointer __p, _A0& __a0, _A1& __a1)
1906 {
1907 ::new((void*)__p) _Tp(__a0, __a1);
1908 }
1909 template <class _A0, class _A1>
1910 _LIBCPP_INLINE_VISIBILITY
1911 void
1912 construct(pointer __p, const _A0& __a0, _A1& __a1)
1913 {
1914 ::new((void*)__p) _Tp(__a0, __a1);
1915 }
1916 template <class _A0, class _A1>
1917 _LIBCPP_INLINE_VISIBILITY
1918 void
1919 construct(pointer __p, _A0& __a0, const _A1& __a1)
1920 {
1921 ::new((void*)__p) _Tp(__a0, __a1);
1922 }
1923 template <class _A0, class _A1>
1924 _LIBCPP_INLINE_VISIBILITY
1925 void
1926 construct(pointer __p, const _A0& __a0, const _A1& __a1)
1927 {
1928 ::new((void*)__p) _Tp(__a0, __a1);
1929 }
1930#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1931 _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1811 _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1812#endif
19321813};
19331814
19341815template <class _Tp>
19351816class _LIBCPP_TEMPLATE_VIS allocator<const _Tp>
19361817{
19371818public:
1938 typedef size_t size_type;
1939 typedef ptrdiff_t difference_type;
1940 typedef const _Tp* pointer;
1941 typedef const _Tp* const_pointer;
1942 typedef const _Tp& reference;
1943 typedef const _Tp& const_reference;
1944 typedef const _Tp value_type;
1819#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS)
1820 _LIBCPP_DEPRECATED_IN_CXX17 typedef size_t size_type;
1821 _LIBCPP_DEPRECATED_IN_CXX17 typedef ptrdiff_t difference_type;
1822 _LIBCPP_DEPRECATED_IN_CXX17 typedef const _Tp* pointer;
1823 _LIBCPP_DEPRECATED_IN_CXX17 typedef const _Tp* const_pointer;
1824 _LIBCPP_DEPRECATED_IN_CXX17 typedef const _Tp& reference;
1825 _LIBCPP_DEPRECATED_IN_CXX17 typedef const _Tp& const_reference;
1826
1827 template <class _Up> struct _LIBCPP_DEPRECATED_IN_CXX17 rebind {typedef allocator<_Up> other;};
1828#endif
1829
1830 typedef const _Tp value_type;
19451831
19461832 typedef true_type propagate_on_container_move_assignment;
19471833 typedef true_type is_always_equal;
19481834
1949 template <class _Up> struct rebind {typedef allocator<_Up> other;};
1950
19511835 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
19521836 allocator() _NOEXCEPT {}
19531837
......@@ -1955,22 +1839,36 @@ public:
19551839 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
19561840 allocator(const allocator<_Up>&) _NOEXCEPT {}
19571841
1958 _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
1842#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS)
1843 _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_INLINE_VISIBILITY
1844 const_pointer address(const_reference __x) const _NOEXCEPT
19591845 {return _VSTD::addressof(__x);}
1960 _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
1846#endif
1847
1848 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY const _Tp* allocate(size_t __n)
19611849 {
1962 if (__n > max_size())
1850 // TODO(mpark): Replace with `allocator_traits<allocator>::max_size(*this)`.
1851 if (__n > (size_t(~0) / sizeof(_Tp)))
19631852 __throw_length_error("allocator<const T>::allocate(size_t n)"
19641853 " 'n' exceeds maximum supported size");
1965 return static_cast<pointer>(_VSTD::__libcpp_allocate(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)));
1854 return static_cast<const _Tp*>(_VSTD::__libcpp_allocate(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)));
19661855 }
1967 _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type __n) _NOEXCEPT
1856
1857#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS)
1858 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_DEPRECATED_IN_CXX17
1859 const _Tp* allocate(size_t __n, const void*) { return allocate(__n); }
1860#endif
1861
1862 _LIBCPP_INLINE_VISIBILITY void deallocate(const _Tp* __p, size_t __n)
19681863 {_VSTD::__libcpp_deallocate((void*) const_cast<_Tp *>(__p), __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp));}
1969 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1864
1865#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS)
1866 _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
19701867 {return size_type(~0) / sizeof(_Tp);}
1868
19711869#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
19721870 template <class _Up, class... _Args>
1973 _LIBCPP_INLINE_VISIBILITY
1871 _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_INLINE_VISIBILITY
19741872 void
19751873 construct(_Up* __p, _Args&&... __args)
19761874 {
......@@ -2029,7 +1927,8 @@ public:
20291927 ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1);
20301928 }
20311929#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
2032 _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1930 _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1931#endif
20331932};
20341933
20351934template <class _Tp, class _Up>
......@@ -2134,39 +2033,39 @@ private:
21342033public:
21352034 typedef _Tp element_type;
21362035
2137 _LIBCPP_INLINE_VISIBILITY explicit auto_ptr(_Tp* __p = 0) throw() : __ptr_(__p) {}
2138 _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr& __p) throw() : __ptr_(__p.release()) {}
2139 template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr<_Up>& __p) throw()
2036 _LIBCPP_INLINE_VISIBILITY explicit auto_ptr(_Tp* __p = 0) _NOEXCEPT : __ptr_(__p) {}
2037 _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr& __p) _NOEXCEPT : __ptr_(__p.release()) {}
2038 template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr<_Up>& __p) _NOEXCEPT
21402039 : __ptr_(__p.release()) {}
2141 _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr& __p) throw()
2040 _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr& __p) _NOEXCEPT
21422041 {reset(__p.release()); return *this;}
2143 template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr<_Up>& __p) throw()
2042 template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr<_Up>& __p) _NOEXCEPT
21442043 {reset(__p.release()); return *this;}
2145 _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr_ref<_Tp> __p) throw()
2044 _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr_ref<_Tp> __p) _NOEXCEPT
21462045 {reset(__p.__ptr_); return *this;}
2147 _LIBCPP_INLINE_VISIBILITY ~auto_ptr() throw() {delete __ptr_;}
2046 _LIBCPP_INLINE_VISIBILITY ~auto_ptr() _NOEXCEPT {delete __ptr_;}
21482047
2149 _LIBCPP_INLINE_VISIBILITY _Tp& operator*() const throw()
2048 _LIBCPP_INLINE_VISIBILITY _Tp& operator*() const _NOEXCEPT
21502049 {return *__ptr_;}
2151 _LIBCPP_INLINE_VISIBILITY _Tp* operator->() const throw() {return __ptr_;}
2152 _LIBCPP_INLINE_VISIBILITY _Tp* get() const throw() {return __ptr_;}
2153 _LIBCPP_INLINE_VISIBILITY _Tp* release() throw()
2050 _LIBCPP_INLINE_VISIBILITY _Tp* operator->() const _NOEXCEPT {return __ptr_;}
2051 _LIBCPP_INLINE_VISIBILITY _Tp* get() const _NOEXCEPT {return __ptr_;}
2052 _LIBCPP_INLINE_VISIBILITY _Tp* release() _NOEXCEPT
21542053 {
21552054 _Tp* __t = __ptr_;
21562055 __ptr_ = 0;
21572056 return __t;
21582057 }
2159 _LIBCPP_INLINE_VISIBILITY void reset(_Tp* __p = 0) throw()
2058 _LIBCPP_INLINE_VISIBILITY void reset(_Tp* __p = 0) _NOEXCEPT
21602059 {
21612060 if (__ptr_ != __p)
21622061 delete __ptr_;
21632062 __ptr_ = __p;
21642063 }
21652064
2166 _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr_ref<_Tp> __p) throw() : __ptr_(__p.__ptr_) {}
2167 template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr_ref<_Up>() throw()
2065 _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr_ref<_Tp> __p) _NOEXCEPT : __ptr_(__p.__ptr_) {}
2066 template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr_ref<_Up>() _NOEXCEPT
21682067 {auto_ptr_ref<_Up> __t; __t.__ptr_ = release(); return __t;}
2169 template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr<_Up>() throw()
2068 template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr<_Up>() _NOEXCEPT
21702069 {return auto_ptr<_Up>(release());}
21712070};
21722071
......@@ -3393,6 +3292,8 @@ class _LIBCPP_EXCEPTION_ABI bad_weak_ptr
33933292 : public std::exception
33943293{
33953294public:
3295 bad_weak_ptr() _NOEXCEPT = default;
3296 bad_weak_ptr(const bad_weak_ptr&) _NOEXCEPT = default;
33963297 virtual ~bad_weak_ptr() _NOEXCEPT;
33973298 virtual const char* what() const _NOEXCEPT;
33983299};
......@@ -3628,15 +3529,25 @@ public:
36283529
36293530template<class _Tp> class _LIBCPP_TEMPLATE_VIS enable_shared_from_this;
36303531
3532template<class _Tp, class _Up>
3533struct __compatible_with
3534#if _LIBCPP_STD_VER > 14
3535 : is_convertible<remove_extent_t<_Tp>*, remove_extent_t<_Up>*> {};
3536#else
3537 : is_convertible<_Tp*, _Up*> {};
3538#endif // _LIBCPP_STD_VER > 14
3539
36313540template<class _Tp>
36323541class _LIBCPP_TEMPLATE_VIS shared_ptr
36333542{
36343543public:
3635 typedef _Tp element_type;
3636
36373544#if _LIBCPP_STD_VER > 14
36383545 typedef weak_ptr<_Tp> weak_type;
3546 typedef remove_extent_t<_Tp> element_type;
3547#else
3548 typedef _Tp element_type;
36393549#endif
3550
36403551private:
36413552 element_type* __ptr_;
36423553 __shared_weak_count* __cntrl_;
......@@ -3649,13 +3560,13 @@ public:
36493560 _LIBCPP_CONSTEXPR shared_ptr(nullptr_t) _NOEXCEPT;
36503561 template<class _Yp>
36513562 explicit shared_ptr(_Yp* __p,
3652 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3563 typename enable_if<__compatible_with<_Yp, element_type>::value, __nat>::type = __nat());
36533564 template<class _Yp, class _Dp>
36543565 shared_ptr(_Yp* __p, _Dp __d,
3655 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3566 typename enable_if<__compatible_with<_Yp, element_type>::value, __nat>::type = __nat());
36563567 template<class _Yp, class _Dp, class _Alloc>
36573568 shared_ptr(_Yp* __p, _Dp __d, _Alloc __a,
3658 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3569 typename enable_if<__compatible_with<_Yp, element_type>::value, __nat>::type = __nat());
36593570 template <class _Dp> shared_ptr(nullptr_t __p, _Dp __d);
36603571 template <class _Dp, class _Alloc> shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a);
36613572 template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(const shared_ptr<_Yp>& __r, element_type* __p) _NOEXCEPT;
......@@ -3664,13 +3575,13 @@ public:
36643575 template<class _Yp>
36653576 _LIBCPP_INLINE_VISIBILITY
36663577 shared_ptr(const shared_ptr<_Yp>& __r,
3667 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat())
3578 typename enable_if<__compatible_with<_Yp, element_type>::value, __nat>::type = __nat())
36683579 _NOEXCEPT;
36693580#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
36703581 _LIBCPP_INLINE_VISIBILITY
36713582 shared_ptr(shared_ptr&& __r) _NOEXCEPT;
36723583 template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(shared_ptr<_Yp>&& __r,
3673 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat())
3584 typename enable_if<__compatible_with<_Yp, element_type>::value, __nat>::type = __nat())
36743585 _NOEXCEPT;
36753586#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
36763587 template<class _Yp> explicit shared_ptr(const weak_ptr<_Yp>& __r,
......@@ -3686,7 +3597,6 @@ public:
36863597 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
36873598#endif
36883599#endif
3689#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
36903600 template <class _Yp, class _Dp>
36913601 shared_ptr(unique_ptr<_Yp, _Dp>&&,
36923602 typename enable_if
......@@ -3705,26 +3615,6 @@ public:
37053615 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
37063616 __nat
37073617 >::type = __nat());
3708#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3709 template <class _Yp, class _Dp>
3710 shared_ptr(unique_ptr<_Yp, _Dp>,
3711 typename enable_if
3712 <
3713 !is_lvalue_reference<_Dp>::value &&
3714 !is_array<_Yp>::value &&
3715 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3716 __nat
3717 >::type = __nat());
3718 template <class _Yp, class _Dp>
3719 shared_ptr(unique_ptr<_Yp, _Dp>,
3720 typename enable_if
3721 <
3722 is_lvalue_reference<_Dp>::value &&
3723 !is_array<_Yp>::value &&
3724 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3725 __nat
3726 >::type = __nat());
3727#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
37283618
37293619 ~shared_ptr();
37303620
......@@ -3733,7 +3623,7 @@ public:
37333623 template<class _Yp>
37343624 typename enable_if
37353625 <
3736 is_convertible<_Yp*, element_type*>::value,
3626 __compatible_with<_Yp, element_type>::value,
37373627 shared_ptr&
37383628 >::type
37393629 _LIBCPP_INLINE_VISIBILITY
......@@ -3744,8 +3634,8 @@ public:
37443634 template<class _Yp>
37453635 typename enable_if
37463636 <
3747 is_convertible<_Yp*, element_type*>::value,
3748 shared_ptr<_Tp>&
3637 __compatible_with<_Yp, element_type>::value,
3638 shared_ptr&
37493639 >::type
37503640 _LIBCPP_INLINE_VISIBILITY
37513641 operator=(shared_ptr<_Yp>&& __r);
......@@ -3795,7 +3685,7 @@ public:
37953685 template<class _Yp>
37963686 typename enable_if
37973687 <
3798 is_convertible<_Yp*, element_type*>::value,
3688 __compatible_with<_Yp, element_type>::value,
37993689 void
38003690 >::type
38013691 _LIBCPP_INLINE_VISIBILITY
......@@ -3803,7 +3693,7 @@ public:
38033693 template<class _Yp, class _Dp>
38043694 typename enable_if
38053695 <
3806 is_convertible<_Yp*, element_type*>::value,
3696 __compatible_with<_Yp, element_type>::value,
38073697 void
38083698 >::type
38093699 _LIBCPP_INLINE_VISIBILITY
......@@ -3811,7 +3701,7 @@ public:
38113701 template<class _Yp, class _Dp, class _Alloc>
38123702 typename enable_if
38133703 <
3814 is_convertible<_Yp*, element_type*>::value,
3704 __compatible_with<_Yp, element_type>::value,
38153705 void
38163706 >::type
38173707 _LIBCPP_INLINE_VISIBILITY
......@@ -3823,7 +3713,12 @@ public:
38233713 typename add_lvalue_reference<element_type>::type operator*() const _NOEXCEPT
38243714 {return *__ptr_;}
38253715 _LIBCPP_INLINE_VISIBILITY
3826 element_type* operator->() const _NOEXCEPT {return __ptr_;}
3716 element_type* operator->() const _NOEXCEPT
3717 {
3718 static_assert(!_VSTD::is_array<_Tp>::value,
3719 "std::shared_ptr<T>::operator-> is only valid when T is not an array type.");
3720 return __ptr_;
3721 }
38273722 _LIBCPP_INLINE_VISIBILITY
38283723 long use_count() const _NOEXCEPT {return __cntrl_ ? __cntrl_->use_count() : 0;}
38293724 _LIBCPP_INLINE_VISIBILITY
......@@ -3843,6 +3738,17 @@ public:
38433738 __owner_equivalent(const shared_ptr& __p) const
38443739 {return __cntrl_ == __p.__cntrl_;}
38453740
3741#if _LIBCPP_STD_VER > 14
3742 typename add_lvalue_reference<element_type>::type
3743 _LIBCPP_INLINE_VISIBILITY
3744 operator[](ptrdiff_t __i) const
3745 {
3746 static_assert(_VSTD::is_array<_Tp>::value,
3747 "std::shared_ptr<T>::operator[] is only valid when T is an array type.");
3748 return __ptr_[__i];
3749 }
3750#endif
3751
38463752#ifndef _LIBCPP_NO_RTTI
38473753 template <class _Dp>
38483754 _LIBCPP_INLINE_VISIBILITY
......@@ -3854,7 +3760,7 @@ public:
38543760
38553761 template<class _Yp, class _CntrlBlk>
38563762 static shared_ptr<_Tp>
3857 __create_with_control_block(_Yp* __p, _CntrlBlk* __cntrl)
3763 __create_with_control_block(_Yp* __p, _CntrlBlk* __cntrl) _NOEXCEPT
38583764 {
38593765 shared_ptr<_Tp> __r;
38603766 __r.__ptr_ = __p;
......@@ -3863,11 +3769,6 @@ public:
38633769 return __r;
38643770 }
38653771
3866 template<class _Alloc, class ..._Args>
3867 static
3868 shared_ptr<_Tp>
3869 allocate_shared(const _Alloc& __a, _Args&& ...__args);
3870
38713772private:
38723773 template <class _Yp, bool = is_function<_Yp>::value>
38733774 struct __shared_ptr_default_allocator
......@@ -3900,10 +3801,28 @@ private:
39003801
39013802 _LIBCPP_INLINE_VISIBILITY void __enable_weak_this(...) _NOEXCEPT {}
39023803
3804 template <class, class _Yp>
3805 struct __shared_ptr_default_delete
3806 : default_delete<_Yp> {};
3807
3808 template <class _Yp, class _Un, size_t _Sz>
3809 struct __shared_ptr_default_delete<_Yp[_Sz], _Un>
3810 : default_delete<_Yp[]> {};
3811
3812 template <class _Yp, class _Un>
3813 struct __shared_ptr_default_delete<_Yp[], _Un>
3814 : default_delete<_Yp[]> {};
3815
39033816 template <class _Up> friend class _LIBCPP_TEMPLATE_VIS shared_ptr;
39043817 template <class _Up> friend class _LIBCPP_TEMPLATE_VIS weak_ptr;
39053818};
39063819
3820#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
3821template<class _Tp>
3822shared_ptr(weak_ptr<_Tp>) -> shared_ptr<_Tp>;
3823template<class _Tp, class _Dp>
3824shared_ptr(unique_ptr<_Tp, _Dp>) -> shared_ptr<_Tp>;
3825#endif
39073826
39083827template<class _Tp>
39093828inline
......@@ -3926,13 +3845,13 @@ shared_ptr<_Tp>::shared_ptr(nullptr_t) _NOEXCEPT
39263845template<class _Tp>
39273846template<class _Yp>
39283847shared_ptr<_Tp>::shared_ptr(_Yp* __p,
3929 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
3848 typename enable_if<__compatible_with<_Yp, element_type>::value, __nat>::type)
39303849 : __ptr_(__p)
39313850{
39323851 unique_ptr<_Yp> __hold(__p);
39333852 typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
3934 typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, _AllocT > _CntrlBlk;
3935 __cntrl_ = new _CntrlBlk(__p, default_delete<_Yp>(), _AllocT());
3853 typedef __shared_ptr_pointer<_Yp*, __shared_ptr_default_delete<_Tp, _Yp>, _AllocT > _CntrlBlk;
3854 __cntrl_ = new _CntrlBlk(__p, __shared_ptr_default_delete<_Tp, _Yp>(), _AllocT());
39363855 __hold.release();
39373856 __enable_weak_this(__p, __p);
39383857}
......@@ -3940,7 +3859,7 @@ shared_ptr<_Tp>::shared_ptr(_Yp* __p,
39403859template<class _Tp>
39413860template<class _Yp, class _Dp>
39423861shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d,
3943 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
3862 typename enable_if<__compatible_with<_Yp, element_type>::value, __nat>::type)
39443863 : __ptr_(__p)
39453864{
39463865#ifndef _LIBCPP_NO_EXCEPTIONS
......@@ -3986,7 +3905,7 @@ shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d)
39863905template<class _Tp>
39873906template<class _Yp, class _Dp, class _Alloc>
39883907shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a,
3989 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
3908 typename enable_if<__compatible_with<_Yp, element_type>::value, __nat>::type)
39903909 : __ptr_(__p)
39913910{
39923911#ifndef _LIBCPP_NO_EXCEPTIONS
......@@ -4064,7 +3983,7 @@ template<class _Tp>
40643983template<class _Yp>
40653984inline
40663985shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r,
4067 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
3986 typename enable_if<__compatible_with<_Yp, element_type>::value, __nat>::type)
40683987 _NOEXCEPT
40693988 : __ptr_(__r.__ptr_),
40703989 __cntrl_(__r.__cntrl_)
......@@ -4089,7 +4008,7 @@ template<class _Tp>
40894008template<class _Yp>
40904009inline
40914010shared_ptr<_Tp>::shared_ptr(shared_ptr<_Yp>&& __r,
4092 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4011 typename enable_if<__compatible_with<_Yp, element_type>::value, __nat>::type)
40934012 _NOEXCEPT
40944013 : __ptr_(__r.__ptr_),
40954014 __cntrl_(__r.__cntrl_)
......@@ -4120,11 +4039,7 @@ shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp> __r,
41204039
41214040template<class _Tp>
41224041template <class _Yp, class _Dp>
4123#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
41244042shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
4125#else
4126shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
4127#endif
41284043 typename enable_if
41294044 <
41304045 !is_lvalue_reference<_Dp>::value &&
......@@ -4150,11 +4065,7 @@ shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
41504065
41514066template<class _Tp>
41524067template <class _Yp, class _Dp>
4153#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
41544068shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
4155#else
4156shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
4157#endif
41584069 typename enable_if
41594070 <
41604071 is_lvalue_reference<_Dp>::value &&
......@@ -4174,32 +4085,12 @@ shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
41744085 typedef __shared_ptr_pointer<_Yp*,
41754086 reference_wrapper<typename remove_reference<_Dp>::type>,
41764087 _AllocT > _CntrlBlk;
4177 __cntrl_ = new _CntrlBlk(__r.get(), ref(__r.get_deleter()), _AllocT());
4088 __cntrl_ = new _CntrlBlk(__r.get(), _VSTD::ref(__r.get_deleter()), _AllocT());
41784089 __enable_weak_this(__r.get(), __r.get());
41794090 }
41804091 __r.release();
41814092}
41824093
4183template<class _Tp>
4184template<class _Alloc, class ..._Args>
4185shared_ptr<_Tp>
4186shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _Args&& ...__args)
4187{
4188 static_assert( is_constructible<_Tp, _Args...>::value, "Can't construct object in allocate_shared" );
4189 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4190 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
4191 typedef __allocator_destructor<_A2> _D2;
4192 _A2 __a2(__a);
4193 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4194 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4195 _CntrlBlk(__a, _VSTD::forward<_Args>(__args)...);
4196 shared_ptr<_Tp> __r;
4197 __r.__ptr_ = __hold2.get()->get();
4198 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
4199 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4200 return __r;
4201}
4202
42034094template<class _Tp>
42044095shared_ptr<_Tp>::~shared_ptr()
42054096{
......@@ -4221,7 +4112,7 @@ template<class _Yp>
42214112inline
42224113typename enable_if
42234114<
4224 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4115 __compatible_with<_Yp, typename shared_ptr<_Tp>::element_type>::value,
42254116 shared_ptr<_Tp>&
42264117>::type
42274118shared_ptr<_Tp>::operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT
......@@ -4246,7 +4137,7 @@ template<class _Yp>
42464137inline
42474138typename enable_if
42484139<
4249 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4140 __compatible_with<_Yp, typename shared_ptr<_Tp>::element_type>::value,
42504141 shared_ptr<_Tp>&
42514142>::type
42524143shared_ptr<_Tp>::operator=(shared_ptr<_Yp>&& __r)
......@@ -4347,7 +4238,7 @@ template<class _Yp>
43474238inline
43484239typename enable_if
43494240<
4350 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4241 __compatible_with<_Yp, typename shared_ptr<_Tp>::element_type>::value,
43514242 void
43524243>::type
43534244shared_ptr<_Tp>::reset(_Yp* __p)
......@@ -4360,7 +4251,7 @@ template<class _Yp, class _Dp>
43604251inline
43614252typename enable_if
43624253<
4363 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4254 __compatible_with<_Yp, typename shared_ptr<_Tp>::element_type>::value,
43644255 void
43654256>::type
43664257shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d)
......@@ -4373,7 +4264,7 @@ template<class _Yp, class _Dp, class _Alloc>
43734264inline
43744265typename enable_if
43754266<
4376 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4267 __compatible_with<_Yp, typename shared_ptr<_Tp>::element_type>::value,
43774268 void
43784269>::type
43794270shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d, _Alloc __a)
......@@ -4412,7 +4303,19 @@ typename enable_if
44124303>::type
44134304allocate_shared(const _Alloc& __a, _Args&& ...__args)
44144305{
4415 return shared_ptr<_Tp>::allocate_shared(__a, _VSTD::forward<_Args>(__args)...);
4306 static_assert( is_constructible<_Tp, _Args...>::value, "Can't construct object in allocate_shared");
4307
4308 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4309 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
4310 typedef __allocator_destructor<_A2> _D2;
4311
4312 _A2 __a2(__a);
4313 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4314 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4315 _CntrlBlk(__a, _VSTD::forward<_Args>(__args)...);
4316
4317 typename shared_ptr<_Tp>::element_type *__p = __hold2.get()->get();
4318 return shared_ptr<_Tp>::__create_with_control_block(__p, _VSTD::addressof(*__hold2.release()));
44164319}
44174320
44184321template<class _Tp, class _Up>
......@@ -4575,41 +4478,41 @@ swap(shared_ptr<_Tp>& __x, shared_ptr<_Tp>& __y) _NOEXCEPT
45754478
45764479template<class _Tp, class _Up>
45774480inline _LIBCPP_INLINE_VISIBILITY
4578typename enable_if
4579<
4580 !is_array<_Tp>::value && !is_array<_Up>::value,
4581 shared_ptr<_Tp>
4582>::type
4481shared_ptr<_Tp>
45834482static_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
45844483{
4585 return shared_ptr<_Tp>(__r, static_cast<_Tp*>(__r.get()));
4484 return shared_ptr<_Tp>(__r,
4485 static_cast<
4486 typename shared_ptr<_Tp>::element_type*>(__r.get()));
45864487}
45874488
45884489template<class _Tp, class _Up>
45894490inline _LIBCPP_INLINE_VISIBILITY
4590typename enable_if
4591<
4592 !is_array<_Tp>::value && !is_array<_Up>::value,
4593 shared_ptr<_Tp>
4594>::type
4491shared_ptr<_Tp>
45954492dynamic_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
45964493{
4597 _Tp* __p = dynamic_cast<_Tp*>(__r.get());
4494 typedef typename shared_ptr<_Tp>::element_type _ET;
4495 _ET* __p = dynamic_cast<_ET*>(__r.get());
45984496 return __p ? shared_ptr<_Tp>(__r, __p) : shared_ptr<_Tp>();
45994497}
46004498
46014499template<class _Tp, class _Up>
4602typename enable_if
4603<
4604 is_array<_Tp>::value == is_array<_Up>::value,
4605 shared_ptr<_Tp>
4606>::type
4500shared_ptr<_Tp>
46074501const_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
46084502{
4609 typedef typename remove_extent<_Tp>::type _RTp;
4503 typedef typename shared_ptr<_Tp>::element_type _RTp;
46104504 return shared_ptr<_Tp>(__r, const_cast<_RTp*>(__r.get()));
46114505}
46124506
4507template<class _Tp, class _Up>
4508shared_ptr<_Tp>
4509reinterpret_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
4510{
4511 return shared_ptr<_Tp>(__r,
4512 reinterpret_cast<
4513 typename shared_ptr<_Tp>::element_type*>(__r.get()));
4514}
4515
46134516#ifndef _LIBCPP_NO_RTTI
46144517
46154518template<class _Dp, class _Tp>
......@@ -4712,6 +4615,11 @@ public:
47124615 template <class _Up> friend class _LIBCPP_TEMPLATE_VIS shared_ptr;
47134616};
47144617
4618#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
4619template<class _Tp>
4620weak_ptr(shared_ptr<_Tp>) -> weak_ptr<_Tp>;
4621#endif
4622
47154623template<class _Tp>
47164624inline
47174625_LIBCPP_CONSTEXPR
......@@ -5008,7 +4916,7 @@ struct _LIBCPP_TEMPLATE_VIS hash<shared_ptr<_Tp> >
50084916 _LIBCPP_INLINE_VISIBILITY
50094917 result_type operator()(const argument_type& __ptr) const _NOEXCEPT
50104918 {
5011 return hash<_Tp*>()(__ptr.get());
4919 return hash<typename shared_ptr<_Tp>::element_type*>()(__ptr.get());
50124920 }
50134921};
50144922
lib/libcxx/include/module.modulemap+23
......@@ -231,6 +231,11 @@ module std [system] {
231231 header "atomic"
232232 export *
233233 }
234 module barrier {
235 requires cplusplus14
236 header "barrier"
237 export *
238 }
234239 module bit {
235240 header "bit"
236241 export *
......@@ -262,6 +267,10 @@ module std [system] {
262267 header "complex"
263268 export *
264269 }
270 module concepts {
271 header "concepts"
272 export *
273 }
265274 module condition_variable {
266275 header "condition_variable"
267276 export *
......@@ -334,6 +343,11 @@ module std [system] {
334343 header "iterator"
335344 export *
336345 }
346 module latch {
347 requires cplusplus14
348 header "latch"
349 export *
350 }
337351 module limits {
338352 header "limits"
339353 export *
......@@ -364,6 +378,10 @@ module std [system] {
364378 header "new"
365379 export *
366380 }
381 module numbers {
382 header "numbers"
383 export *
384 }
367385 module numeric {
368386 header "numeric"
369387 export *
......@@ -400,6 +418,11 @@ module std [system] {
400418 header "scoped_allocator"
401419 export *
402420 }
421 module semaphore {
422 requires cplusplus14
423 header "semaphore"
424 export *
425 }
403426 module set {
404427 header "set"
405428 export initializer_list
lib/libcxx/include/numbers created+141
......@@ -0,0 +1,141 @@
1// -*- C++ -*-
2//===---------------------------- numbers ---------------------------------===//
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_NUMBERS
11#define _LIBCPP_NUMBERS
12
13/*
14 numbers synopsis
15
16namespace std::numbers {
17 template<class T> inline constexpr T e_v = unspecified;
18 template<class T> inline constexpr T log2e_v = unspecified;
19 template<class T> inline constexpr T log10e_v = unspecified;
20 template<class T> inline constexpr T pi_v = unspecified;
21 template<class T> inline constexpr T inv_pi_v = unspecified;
22 template<class T> inline constexpr T inv_sqrtpi_v = unspecified;
23 template<class T> inline constexpr T ln2_v = unspecified;
24 template<class T> inline constexpr T ln10_v = unspecified;
25 template<class T> inline constexpr T sqrt2_v = unspecified;
26 template<class T> inline constexpr T sqrt3_v = unspecified;
27 template<class T> inline constexpr T inv_sqrt3_v = unspecified;
28 template<class T> inline constexpr T egamma_v = unspecified;
29 template<class T> inline constexpr T phi_v = unspecified;
30
31 template<floating_point T> inline constexpr T e_v<T> = see below;
32 template<floating_point T> inline constexpr T log2e_v<T> = see below;
33 template<floating_point T> inline constexpr T log10e_v<T> = see below;
34 template<floating_point T> inline constexpr T pi_v<T> = see below;
35 template<floating_point T> inline constexpr T inv_pi_v<T> = see below;
36 template<floating_point T> inline constexpr T inv_sqrtpi_v<T> = see below;
37 template<floating_point T> inline constexpr T ln2_v<T> = see below;
38 template<floating_point T> inline constexpr T ln10_v<T> = see below;
39 template<floating_point T> inline constexpr T sqrt2_v<T> = see below;
40 template<floating_point T> inline constexpr T sqrt3_v<T> = see below;
41 template<floating_point T> inline constexpr T inv_sqrt3_v<T> = see below;
42 template<floating_point T> inline constexpr T egamma_v<T> = see below;
43 template<floating_point T> inline constexpr T phi_v<T> = see below;
44
45 inline constexpr double e = e_v<double>;
46 inline constexpr double log2e = log2e_v<double>;
47 inline constexpr double log10e = log10e_v<double>;
48 inline constexpr double pi = pi_v<double>;
49 inline constexpr double inv_pi = inv_pi_v<double>;
50 inline constexpr double inv_sqrtpi = inv_sqrtpi_v<double>;
51 inline constexpr double ln2 = ln2_v<double>;
52 inline constexpr double ln10 = ln10_v<double>;
53 inline constexpr double sqrt2 = sqrt2_v<double>;
54 inline constexpr double sqrt3 = sqrt3_v<double>;
55 inline constexpr double inv_sqrt3 = inv_sqrt3_v<double>;
56 inline constexpr double egamma = egamma_v<double>;
57 inline constexpr double phi = phi_v<double>;
58}
59*/
60
61#include <__config>
62
63#if _LIBCPP_STD_VER > 17 && defined(__cpp_concepts) && __cpp_concepts >= 201811L
64
65#include <type_traits>
66#include <version>
67
68#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
69#pragma GCC system_header
70#endif
71
72_LIBCPP_PUSH_MACROS
73#include <__undef_macros>
74
75_LIBCPP_BEGIN_NAMESPACE_STD
76
77namespace numbers {
78
79template <class T>
80inline constexpr bool __false = false;
81
82template <class T>
83struct __illformed
84{
85 static_assert(__false<T>, "A program that instantiates a primary template of a mathematical constant variable template is ill-formed.");
86};
87
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 <class T>
103concept __floating_point = std::is_floating_point_v<T>;
104
105template <__floating_point T> inline constexpr T e_v<T> = 2.718281828459045235360287471352662;
106template <__floating_point T> inline constexpr T log2e_v<T> = 1.442695040888963407359924681001892;
107template <__floating_point T> inline constexpr T log10e_v<T> = 0.434294481903251827651128918916605;
108template <__floating_point T> inline constexpr T pi_v<T> = 3.141592653589793238462643383279502;
109template <__floating_point T> inline constexpr T inv_pi_v<T> = 0.318309886183790671537767526745028;
110template <__floating_point T> inline constexpr T inv_sqrtpi_v<T> = 0.564189583547756286948079451560772;
111template <__floating_point T> inline constexpr T ln2_v<T> = 0.693147180559945309417232121458176;
112template <__floating_point T> inline constexpr T ln10_v<T> = 2.302585092994045684017991454684364;
113template <__floating_point T> inline constexpr T sqrt2_v<T> = 1.414213562373095048801688724209698;
114template <__floating_point T> inline constexpr T sqrt3_v<T> = 1.732050807568877293527446341505872;
115template <__floating_point T> inline constexpr T inv_sqrt3_v<T> = 0.577350269189625764509148780501957;
116template <__floating_point T> inline constexpr T egamma_v<T> = 0.577215664901532860606512090082402;
117template <__floating_point T> inline constexpr T phi_v<T> = 1.618033988749894848204586834365638;
118
119inline constexpr double e = e_v<double>;
120inline constexpr double log2e = log2e_v<double>;
121inline constexpr double log10e = log10e_v<double>;
122inline constexpr double pi = pi_v<double>;
123inline constexpr double inv_pi = inv_pi_v<double>;
124inline constexpr double inv_sqrtpi = inv_sqrtpi_v<double>;
125inline constexpr double ln2 = ln2_v<double>;
126inline constexpr double ln10 = ln10_v<double>;
127inline constexpr double sqrt2 = sqrt2_v<double>;
128inline constexpr double sqrt3 = sqrt3_v<double>;
129inline constexpr double inv_sqrt3 = inv_sqrt3_v<double>;
130inline constexpr double egamma = egamma_v<double>;
131inline constexpr double phi = phi_v<double>;
132
133} // namespace numbers
134
135_LIBCPP_END_NAMESPACE_STD
136
137_LIBCPP_POP_MACROS
138
139#endif //_LIBCPP_STD_VER > 17 && defined(__cpp_concepts) && __cpp_concepts >= 201811L
140
141#endif // _LIBCPP_NUMBERS
lib/libcxx/include/ostream+3-3
......@@ -999,7 +999,7 @@ basic_ostream<_CharT, _Traits>::seekp(off_type __off, ios_base::seekdir __dir)
999999}
10001000
10011001template <class _CharT, class _Traits>
1002inline _LIBCPP_INLINE_VISIBILITY
1002inline
10031003basic_ostream<_CharT, _Traits>&
10041004endl(basic_ostream<_CharT, _Traits>& __os)
10051005{
......@@ -1009,7 +1009,7 @@ endl(basic_ostream<_CharT, _Traits>& __os)
10091009}
10101010
10111011template <class _CharT, class _Traits>
1012inline _LIBCPP_INLINE_VISIBILITY
1012inline
10131013basic_ostream<_CharT, _Traits>&
10141014ends(basic_ostream<_CharT, _Traits>& __os)
10151015{
......@@ -1018,7 +1018,7 @@ ends(basic_ostream<_CharT, _Traits>& __os)
10181018}
10191019
10201020template <class _CharT, class _Traits>
1021inline _LIBCPP_INLINE_VISIBILITY
1021inline
10221022basic_ostream<_CharT, _Traits>&
10231023flush(basic_ostream<_CharT, _Traits>& __os)
10241024{
lib/libcxx/include/random+5
......@@ -4048,10 +4048,12 @@ binomial_distribution<_IntType>::operator()(_URNG& __g, const param_type& __pr)
40484048 result_type __rd = __ru;
40494049 while (true)
40504050 {
4051 bool __break = true;
40514052 if (__rd >= 1)
40524053 {
40534054 __pd *= __rd / (__pr.__odds_ratio_ * (__pr.__t_ - __rd + 1));
40544055 __u -= __pd;
4056 __break = false;
40554057 if (__u < 0)
40564058 return __rd - 1;
40574059 }
......@@ -4062,9 +4064,12 @@ binomial_distribution<_IntType>::operator()(_URNG& __g, const param_type& __pr)
40624064 {
40634065 __pu *= (__pr.__t_ - __ru + 1) * __pr.__odds_ratio_ / __ru;
40644066 __u -= __pu;
4067 __break = false;
40654068 if (__u < 0)
40664069 return __ru;
40674070 }
4071 if (__break)
4072 return 0;
40684073 }
40694074}
40704075
lib/libcxx/include/regex+47-21
......@@ -21,7 +21,7 @@ namespace std
2121namespace regex_constants
2222{
2323
24emum syntax_option_type
24enum syntax_option_type
2525{
2626 icase = unspecified,
2727 nosubs = unspecified,
......@@ -631,7 +631,7 @@ template <class OutputIterator, class BidirectionalIterator,
631631 const basic_regex<charT, traits>& e, const charT* fmt,
632632 regex_constants::match_flag_type flags = regex_constants::match_default);
633633
634template <class traits, class charT, class ST, class SA, class FST, class FSA>>
634template <class traits, class charT, class ST, class SA, class FST, class FSA>
635635 basic_string<charT, ST, SA>
636636 regex_replace(const basic_string<charT, ST, SA>& s,
637637 const basic_regex<charT, traits>& e,
......@@ -675,9 +675,9 @@ public:
675675 regex_iterator(BidirectionalIterator a, BidirectionalIterator b,
676676 const regex_type& re,
677677 regex_constants::match_flag_type m = regex_constants::match_default);
678 regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
679 const regex_type&& __re,
680 regex_constants::match_flag_type __m
678 regex_iterator(BidirectionalIterator a, BidirectionalIterator b,
679 const regex_type&& re,
680 regex_constants::match_flag_type m
681681 = regex_constants::match_default) = delete; // C++14
682682 regex_iterator(const regex_iterator&);
683683 regex_iterator& operator=(const regex_iterator&);
......@@ -698,7 +698,7 @@ typedef regex_iterator<string::const_iterator> sregex_iterator;
698698typedef regex_iterator<wstring::const_iterator> wsregex_iterator;
699699
700700template <class BidirectionalIterator,
701 class charT = typename iterator_traits< BidirectionalIterator>::value_type,
701 class charT = typename iterator_traits<BidirectionalIterator>::value_type,
702702 class traits = regex_traits<charT>>
703703class regex_token_iterator
704704{
......@@ -735,8 +735,8 @@ public:
735735 regex_constants::match_flag_type m = regex_constants::match_default);
736736 template <size_t N>
737737 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
738 const regex_type& re, const int (&submatches)[N],
739 regex_constants::match_flag_type m = regex_constants::match_default) = delete // C++14;
738 const regex_type&& re, const int (&submatches)[N],
739 regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14
740740 regex_token_iterator(const regex_token_iterator&);
741741 regex_token_iterator& operator=(const regex_token_iterator&);
742742
......@@ -977,7 +977,8 @@ class _LIBCPP_EXCEPTION_ABI regex_error
977977 regex_constants::error_type __code_;
978978public:
979979 explicit regex_error(regex_constants::error_type __ecode);
980 virtual ~regex_error() throw();
980 regex_error(const regex_error&) _NOEXCEPT = default;
981 virtual ~regex_error() _NOEXCEPT;
981982 _LIBCPP_INLINE_VISIBILITY
982983 regex_constants::error_type code() const {return __code_;}
983984};
......@@ -1000,7 +1001,19 @@ public:
10001001 typedef _CharT char_type;
10011002 typedef basic_string<char_type> string_type;
10021003 typedef locale locale_type;
1004#ifdef __BIONIC__
1005 // Originally bionic's ctype_base used its own ctype masks because the
1006 // builtin ctype implementation wasn't in libc++ yet. Bionic's ctype mask
1007 // was only 8 bits wide and already saturated, so it used a wider type here
1008 // to make room for __regex_word (then a part of this class rather than
1009 // ctype_base). Bionic has since moved to the builtin ctype_base
1010 // implementation, but this was not updated to match. Since then Android has
1011 // needed to maintain a stable libc++ ABI, and this can't be changed without
1012 // an ABI break.
1013 typedef uint16_t char_class_type;
1014#else
10031015 typedef ctype_base::mask char_class_type;
1016#endif
10041017
10051018 static const char_class_type __regex_word = ctype_base::__regex_word;
10061019private:
......@@ -2837,6 +2850,8 @@ private:
28372850 __parse_awk_escape(_ForwardIterator __first, _ForwardIterator __last,
28382851 basic_string<_CharT>* __str = nullptr);
28392852
2853 bool __test_back_ref(_CharT c);
2854
28402855 _LIBCPP_INLINE_VISIBILITY
28412856 void __push_l_anchor();
28422857 void __push_r_anchor();
......@@ -3408,18 +3423,8 @@ basic_regex<_CharT, _Traits>::__parse_BACKREF(_ForwardIterator __first,
34083423 if (__first != __last)
34093424 {
34103425 _ForwardIterator __temp = _VSTD::next(__first);
3411 if (__temp != __last)
3412 {
3413 if (*__first == '\\')
3414 {
3415 int __val = __traits_.value(*__temp, 10);
3416 if (__val >= 1 && __val <= 9)
3417 {
3418 __push_back_ref(__val);
3419 __first = ++__temp;
3420 }
3421 }
3422 }
3426 if (__temp != __last && *__first == '\\' && __test_back_ref(*__temp))
3427 __first = ++__temp;
34233428 }
34243429 return __first;
34253430}
......@@ -3547,6 +3552,8 @@ basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR_ERE(_ForwardIterator __first,
35473552 default:
35483553 if (__get_grammar(__flags_) == awk)
35493554 __first = __parse_awk_escape(++__first, __last);
3555 else if(__test_back_ref(*__temp))
3556 __first = ++__temp;
35503557 break;
35513558 }
35523559 }
......@@ -4660,6 +4667,22 @@ basic_regex<_CharT, _Traits>::__parse_egrep(_ForwardIterator __first,
46604667 return __first;
46614668}
46624669
4670template <class _CharT, class _Traits>
4671bool
4672basic_regex<_CharT, _Traits>::__test_back_ref(_CharT c)
4673{
4674 unsigned __val = __traits_.value(c, 10);
4675 if (__val >= 1 && __val <= 9)
4676 {
4677 if (__val > mark_count())
4678 __throw_regex_error<regex_constants::error_backref>();
4679 __push_back_ref(__val);
4680 return true;
4681 }
4682
4683 return false;
4684}
4685
46634686template <class _CharT, class _Traits>
46644687void
46654688basic_regex<_CharT, _Traits>::__push_loop(size_t __min, size_t __max,
......@@ -5917,6 +5940,9 @@ basic_regex<_CharT, _Traits>::__search(
59175940 match_results<const _CharT*, _Allocator>& __m,
59185941 regex_constants::match_flag_type __flags) const
59195942{
5943 if (__flags & regex_constants::match_prev_avail)
5944 __flags &= ~(regex_constants::match_not_bol | regex_constants::match_not_bow);
5945
59205946 __m.__init(1 + mark_count(), __first, __last,
59215947 __flags & regex_constants::__no_update_pos);
59225948 if (__match_at_start(__first, __last, __m, __flags,
lib/libcxx/include/semaphore created+235
......@@ -0,0 +1,235 @@
1// -*- C++ -*-
2//===--------------------------- semaphore --------------------------------===//
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_SEMAPHORE
11#define _LIBCPP_SEMAPHORE
12
13/*
14 semaphore synopsis
15
16namespace std {
17
18template<ptrdiff_t least_max_value = implementation-defined>
19class counting_semaphore
20{
21public:
22static constexpr ptrdiff_t max() noexcept;
23
24constexpr explicit counting_semaphore(ptrdiff_t desired);
25~counting_semaphore();
26
27counting_semaphore(const counting_semaphore&) = delete;
28counting_semaphore& operator=(const counting_semaphore&) = delete;
29
30void release(ptrdiff_t update = 1);
31void acquire();
32bool try_acquire() noexcept;
33template<class Rep, class Period>
34 bool try_acquire_for(const chrono::duration<Rep, Period>& rel_time);
35template<class Clock, class Duration>
36 bool try_acquire_until(const chrono::time_point<Clock, Duration>& abs_time);
37
38private:
39ptrdiff_t counter; // exposition only
40};
41
42using binary_semaphore = counting_semaphore<1>;
43
44}
45
46*/
47
48#include <__config>
49#include <__threading_support>
50#include <atomic>
51#include <cassert>
52
53#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
54#pragma GCC system_header
55#endif
56
57#ifdef _LIBCPP_HAS_NO_THREADS
58# error <semaphore> is not supported on this single threaded system
59#endif
60
61#if _LIBCPP_STD_VER >= 14
62
63_LIBCPP_BEGIN_NAMESPACE_STD
64
65/*
66
67__atomic_semaphore_base is the general-case implementation, to be used for
68user-requested least-max values that exceed the OS implementation support
69(incl. when the OS has no support of its own) and for binary semaphores.
70
71It is a typical Dijsktra semaphore algorithm over atomics, wait and notify
72functions. It avoids contention against users' own use of those facilities.
73
74*/
75
76class __atomic_semaphore_base
77{
78 __atomic_base<ptrdiff_t> __a;
79
80public:
81 _LIBCPP_INLINE_VISIBILITY
82 __atomic_semaphore_base(ptrdiff_t __count) : __a(__count)
83 {
84 }
85 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
86 void release(ptrdiff_t __update = 1)
87 {
88 if(0 < __a.fetch_add(__update, memory_order_release))
89 ;
90 else if(__update > 1)
91 __a.notify_all();
92 else
93 __a.notify_one();
94 }
95 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
96 void acquire()
97 {
98 auto const __test_fn = [=]() -> bool {
99 auto __old = __a.load(memory_order_relaxed);
100 return (__old != 0) && __a.compare_exchange_strong(__old, __old - 1, memory_order_acquire, memory_order_relaxed);
101 };
102 __cxx_atomic_wait(&__a.__a_, __test_fn);
103 }
104 template <class Rep, class Period>
105 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
106 bool try_acquire_for(chrono::duration<Rep, Period> const& __rel_time)
107 {
108 auto const __test_fn = [=]() -> bool {
109 auto __old = __a.load(memory_order_acquire);
110 while(1) {
111 if (__old == 0)
112 return false;
113 if(__a.compare_exchange_strong(__old, __old - 1, memory_order_acquire, memory_order_relaxed))
114 return true;
115 }
116 };
117 return __libcpp_thread_poll_with_backoff(__test_fn, __libcpp_timed_backoff_policy(), __rel_time);
118 }
119};
120
121#ifndef _LIBCPP_NO_NATIVE_SEMAPHORES
122
123/*
124
125__platform_semaphore_base a simple wrapper for the OS semaphore type. That
126is, every call is routed to the OS in the most direct manner possible.
127
128*/
129
130class __platform_semaphore_base
131{
132 __libcpp_semaphore_t __semaphore;
133
134public:
135 _LIBCPP_INLINE_VISIBILITY
136 __platform_semaphore_base(ptrdiff_t __count) :
137 __semaphore()
138 {
139 __libcpp_semaphore_init(&__semaphore, __count);
140 }
141 _LIBCPP_INLINE_VISIBILITY
142 ~__platform_semaphore_base() {
143 __libcpp_semaphore_destroy(&__semaphore);
144 }
145 _LIBCPP_INLINE_VISIBILITY
146 void release(ptrdiff_t __update)
147 {
148 for(; __update; --__update)
149 __libcpp_semaphore_post(&__semaphore);
150 }
151 _LIBCPP_INLINE_VISIBILITY
152 void acquire()
153 {
154 __libcpp_semaphore_wait(&__semaphore);
155 }
156 _LIBCPP_INLINE_VISIBILITY
157 bool try_acquire_for(chrono::nanoseconds __rel_time)
158 {
159 return __libcpp_semaphore_wait_timed(&__semaphore, __rel_time);
160 }
161};
162
163template<ptrdiff_t __least_max_value>
164using __semaphore_base =
165 typename conditional<(__least_max_value > 1 && __least_max_value <= _LIBCPP_SEMAPHORE_MAX),
166 __platform_semaphore_base,
167 __atomic_semaphore_base>::type;
168
169#else
170
171template<ptrdiff_t __least_max_value>
172using __semaphore_base =
173 __atomic_semaphore_base;
174
175#define _LIBCPP_SEMAPHORE_MAX (numeric_limits<ptrdiff_t>::max())
176
177#endif //_LIBCPP_NO_NATIVE_SEMAPHORES
178
179template<ptrdiff_t __least_max_value = _LIBCPP_SEMAPHORE_MAX>
180class counting_semaphore
181{
182 __semaphore_base<__least_max_value> __semaphore;
183
184public:
185 static constexpr ptrdiff_t max() noexcept {
186 return __least_max_value;
187 }
188
189 _LIBCPP_INLINE_VISIBILITY
190 counting_semaphore(ptrdiff_t __count = 0) : __semaphore(__count) { }
191 ~counting_semaphore() = default;
192
193 counting_semaphore(const counting_semaphore&) = delete;
194 counting_semaphore& operator=(const counting_semaphore&) = delete;
195
196 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
197 void release(ptrdiff_t __update = 1)
198 {
199 __semaphore.release(__update);
200 }
201 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
202 void acquire()
203 {
204 __semaphore.acquire();
205 }
206 template<class Rep, class Period>
207 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
208 bool try_acquire_for(chrono::duration<Rep, Period> const& __rel_time)
209 {
210 return __semaphore.try_acquire_for(chrono::duration_cast<chrono::nanoseconds>(__rel_time));
211 }
212 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
213 bool try_acquire()
214 {
215 return try_acquire_for(chrono::nanoseconds::zero());
216 }
217 template <class Clock, class Duration>
218 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
219 bool try_acquire_until(chrono::time_point<Clock, Duration> const& __abs_time)
220 {
221 auto const current = Clock::now();
222 if(current >= __abs_time)
223 return try_acquire();
224 else
225 return try_acquire_for(__abs_time - current);
226 }
227};
228
229using binary_semaphore = counting_semaphore<1>;
230
231_LIBCPP_END_NAMESPACE_STD
232
233#endif // _LIBCPP_STD_VER >= 14
234
235#endif //_LIBCPP_SEMAPHORE
lib/libcxx/include/set+12-6
......@@ -216,7 +216,8 @@ swap(set<Key, Compare, Allocator>& x, set<Key, Compare, Allocator>& y)
216216 noexcept(noexcept(x.swap(y)));
217217
218218template <class Key, class Compare, class Allocator, class Predicate>
219 void erase_if(set<Key, Compare, Allocator>& c, Predicate pred); // C++20
219typename set<Key, Compare, Allocator>::size_type
220erase_if(set<Key, Compare, Allocator>& c, Predicate pred); // C++20
220221
221222template <class Key, class Compare = less<Key>,
222223 class Allocator = allocator<Key>>
......@@ -417,7 +418,8 @@ swap(multiset<Key, Compare, Allocator>& x, multiset<Key, Compare, Allocator>& y)
417418 noexcept(noexcept(x.swap(y)));
418419
419420template <class Key, class Compare, class Allocator, class Predicate>
420 void erase_if(multiset<Key, Compare, Allocator>& c, Predicate pred); // C++20
421typename multiset<Key, Compare, Allocator>::size_type
422erase_if(multiset<Key, Compare, Allocator>& c, Predicate pred); // C++20
421423
422424} // std
423425
......@@ -960,8 +962,10 @@ swap(set<_Key, _Compare, _Allocator>& __x,
960962#if _LIBCPP_STD_VER > 17
961963template <class _Key, class _Compare, class _Allocator, class _Predicate>
962964inline _LIBCPP_INLINE_VISIBILITY
963void erase_if(set<_Key, _Compare, _Allocator>& __c, _Predicate __pred)
964{ __libcpp_erase_if_container(__c, __pred); }
965 typename set<_Key, _Compare, _Allocator>::size_type
966 erase_if(set<_Key, _Compare, _Allocator>& __c, _Predicate __pred) {
967 return __libcpp_erase_if_container(__c, __pred);
968}
965969#endif
966970
967971template <class _Key, class _Compare = less<_Key>,
......@@ -1484,8 +1488,10 @@ swap(multiset<_Key, _Compare, _Allocator>& __x,
14841488#if _LIBCPP_STD_VER > 17
14851489template <class _Key, class _Compare, class _Allocator, class _Predicate>
14861490inline _LIBCPP_INLINE_VISIBILITY
1487void erase_if(multiset<_Key, _Compare, _Allocator>& __c, _Predicate __pred)
1488{ __libcpp_erase_if_container(__c, __pred); }
1491 typename multiset<_Key, _Compare, _Allocator>::size_type
1492 erase_if(multiset<_Key, _Compare, _Allocator>& __c, _Predicate __pred) {
1493 return __libcpp_erase_if_container(__c, __pred);
1494}
14891495#endif
14901496
14911497_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/span+64-106
......@@ -46,15 +46,13 @@ public:
4646 using reference = element_type&;
4747 using const_reference = const element_type&;
4848 using iterator = implementation-defined;
49 using const_iterator = implementation-defined;
5049 using reverse_iterator = std::reverse_iterator<iterator>;
51 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
5250 static constexpr size_type extent = Extent;
5351
5452 // [span.cons], span constructors, copy, assignment, and destructor
5553 constexpr span() noexcept;
56 constexpr span(pointer ptr, size_type count);
57 constexpr span(pointer firstElem, pointer lastElem);
54 constexpr explicit(Extent != dynamic_extent) span(pointer ptr, size_type count);
55 constexpr explicit(Extent != dynamic_extent) span(pointer firstElem, pointer lastElem);
5856 template <size_t N>
5957 constexpr span(element_type (&arr)[N]) noexcept;
6058 template <size_t N>
......@@ -62,12 +60,12 @@ public:
6260 template <size_t N>
6361 constexpr span(const array<value_type, N>& arr) noexcept;
6462 template <class Container>
65 constexpr span(Container& cont);
63 constexpr explicit(Extent != dynamic_extent) span(Container& cont);
6664 template <class Container>
67 constexpr span(const Container& cont);
65 constexpr explicit(Extent != dynamic_extent) span(const Container& cont);
6866 constexpr span(const span& other) noexcept = default;
6967 template <class OtherElementType, size_t OtherExtent>
70 constexpr span(const span<OtherElementType, OtherExtent>& s) noexcept;
68 constexpr explicit(Extent != dynamic_extent) span(const span<OtherElementType, OtherExtent>& s) noexcept;
7169 ~span() noexcept = default;
7270 constexpr span& operator=(const span& other) noexcept = default;
7371
......@@ -97,12 +95,8 @@ public:
9795 // [span.iterators], span iterator support
9896 constexpr iterator begin() const noexcept;
9997 constexpr iterator end() const noexcept;
100 constexpr const_iterator cbegin() const noexcept;
101 constexpr const_iterator cend() const noexcept;
10298 constexpr reverse_iterator rbegin() const noexcept;
10399 constexpr reverse_iterator rend() const noexcept;
104 constexpr const_reverse_iterator crbegin() const noexcept;
105 constexpr const_reverse_iterator crend() const noexcept;
106100
107101private:
108102 pointer data_; // exposition only
......@@ -129,11 +123,10 @@ template<class Container>
129123*/
130124
131125#include <__config>
132#include <cstddef> // for ptrdiff_t
133#include <iterator> // for iterators
134126#include <array> // for array
135#include <type_traits> // for remove_cv, etc
136127#include <cstddef> // for byte
128#include <iterator> // for iterators
129#include <type_traits> // for remove_cv, etc
137130
138131#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
139132#pragma GCC system_header
......@@ -143,7 +136,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
143136
144137#if _LIBCPP_STD_VER > 17
145138
146inline constexpr size_t dynamic_extent = numeric_limits<size_t>::max();
139inline constexpr size_t dynamic_extent = (numeric_limits<size_t>::max)();
147140template <typename _Tp, size_t _Extent = dynamic_extent> class span;
148141
149142
......@@ -202,27 +195,49 @@ public:
202195 using reference = _Tp &;
203196 using const_reference = const _Tp &;
204197 using iterator = __wrap_iter<pointer>;
205 using const_iterator = __wrap_iter<const_pointer>;
206198 using reverse_iterator = _VSTD::reverse_iterator<iterator>;
207 using const_reverse_iterator = _VSTD::reverse_iterator<const_iterator>;
208199
209200 static constexpr size_type extent = _Extent;
210201
211202// [span.cons], span constructors, copy, assignment, and destructor
212 _LIBCPP_INLINE_VISIBILITY constexpr span() noexcept : __data{nullptr}
213 { static_assert(_Extent == 0, "Can't default construct a statically sized span with size > 0"); }
203 template <size_t _Sz = _Extent, enable_if_t<_Sz == 0, nullptr_t> = nullptr>
204 _LIBCPP_INLINE_VISIBILITY constexpr span() noexcept : __data{nullptr} {}
214205
215206 constexpr span (const span&) noexcept = default;
216207 constexpr span& operator=(const span&) noexcept = default;
217208
218 _LIBCPP_INLINE_VISIBILITY constexpr span(pointer __ptr, size_type __count) : __data{__ptr}
209 _LIBCPP_INLINE_VISIBILITY constexpr explicit span(pointer __ptr, size_type __count) : __data{__ptr}
219210 { (void)__count; _LIBCPP_ASSERT(_Extent == __count, "size mismatch in span's constructor (ptr, len)"); }
220 _LIBCPP_INLINE_VISIBILITY constexpr span(pointer __f, pointer __l) : __data{__f}
211 _LIBCPP_INLINE_VISIBILITY constexpr explicit span(pointer __f, pointer __l) : __data{__f}
221212 { (void)__l; _LIBCPP_ASSERT(_Extent == distance(__f, __l), "size mismatch in span's constructor (ptr, ptr)"); }
222213
223214 _LIBCPP_INLINE_VISIBILITY constexpr span(element_type (&__arr)[_Extent]) noexcept : __data{__arr} {}
224 _LIBCPP_INLINE_VISIBILITY constexpr span( array<value_type, _Extent>& __arr) noexcept : __data{__arr.data()} {}
225 _LIBCPP_INLINE_VISIBILITY constexpr span(const array<value_type, _Extent>& __arr) noexcept : __data{__arr.data()} {}
215
216 template <class _OtherElementType,
217 enable_if_t<is_convertible_v<_OtherElementType(*)[], element_type (*)[]>, nullptr_t> = nullptr>
218 _LIBCPP_INLINE_VISIBILITY
219 constexpr span(array<_OtherElementType, _Extent>& __arr) noexcept : __data{__arr.data()} {}
220
221 template <class _OtherElementType,
222 enable_if_t<is_convertible_v<const _OtherElementType(*)[], element_type (*)[]>, nullptr_t> = nullptr>
223 _LIBCPP_INLINE_VISIBILITY
224 constexpr span(const array<_OtherElementType, _Extent>& __arr) noexcept : __data{__arr.data()} {}
225
226 template <class _Container>
227 _LIBCPP_INLINE_VISIBILITY
228 constexpr explicit span( _Container& __c,
229 enable_if_t<__is_span_compatible_container<_Container, _Tp>::value, nullptr_t> = nullptr)
230 : __data{_VSTD::data(__c)} {
231 _LIBCPP_ASSERT(_Extent == _VSTD::size(__c), "size mismatch in span's constructor (range)");
232 }
233
234 template <class _Container>
235 _LIBCPP_INLINE_VISIBILITY
236 constexpr explicit span(const _Container& __c,
237 enable_if_t<__is_span_compatible_container<const _Container, _Tp>::value, nullptr_t> = nullptr)
238 : __data{_VSTD::data(__c)} {
239 _LIBCPP_ASSERT(_Extent == _VSTD::size(__c), "size mismatch in span's constructor (range)");
240 }
226241
227242 template <class _OtherElementType>
228243 _LIBCPP_INLINE_VISIBILITY
......@@ -234,7 +249,7 @@ public:
234249
235250 template <class _OtherElementType>
236251 _LIBCPP_INLINE_VISIBILITY
237 constexpr span(const span<_OtherElementType, dynamic_extent>& __other,
252 constexpr explicit span(const span<_OtherElementType, dynamic_extent>& __other,
238253 enable_if_t<
239254 is_convertible_v<_OtherElementType(*)[], element_type (*)[]>,
240255 nullptr_t> = nullptr) noexcept
......@@ -248,7 +263,7 @@ public:
248263 constexpr span<element_type, _Count> first() const noexcept
249264 {
250265 static_assert(_Count <= _Extent, "Count out of range in span::first()");
251 return {data(), _Count};
266 return span<element_type, _Count>{data(), _Count};
252267 }
253268
254269 template <size_t _Count>
......@@ -256,7 +271,7 @@ public:
256271 constexpr span<element_type, _Count> last() const noexcept
257272 {
258273 static_assert(_Count <= _Extent, "Count out of range in span::last()");
259 return {data() + size() - _Count, _Count};
274 return span<element_type, _Count>{data() + size() - _Count, _Count};
260275 }
261276
262277 _LIBCPP_INLINE_VISIBILITY
......@@ -279,7 +294,10 @@ public:
279294 -> span<element_type, _Count != dynamic_extent ? _Count : _Extent - _Offset>
280295 {
281296 static_assert(_Offset <= _Extent, "Offset out of range in span::subspan()");
282 return {data() + _Offset, _Count == dynamic_extent ? size() - _Offset : _Count};
297 static_assert(_Count == dynamic_extent || _Count <= _Extent - _Offset, "Offset + count out of range in span::subspan()");
298
299 using _ReturnType = span<element_type, _Count != dynamic_extent ? _Count : _Extent - _Offset>;
300 return _ReturnType{data() + _Offset, _Count == dynamic_extent ? size() - _Offset : _Count};
283301 }
284302
285303
......@@ -291,7 +309,7 @@ public:
291309 _LIBCPP_ASSERT(__count <= size() || __count == dynamic_extent, "Count out of range in span::subspan(offset, count)");
292310 if (__count == dynamic_extent)
293311 return {data() + __offset, size() - __offset};
294 _LIBCPP_ASSERT(__offset <= size() - __count, "count + offset out of range in span::subspan(offset, count)");
312 _LIBCPP_ASSERT(__count <= size() - __offset, "Offset + count out of range in span::subspan(offset, count)");
295313 return {data() + __offset, __count};
296314 }
297315
......@@ -301,19 +319,19 @@ public:
301319
302320 _LIBCPP_INLINE_VISIBILITY constexpr reference operator[](size_type __idx) const noexcept
303321 {
304 _LIBCPP_ASSERT(__idx >= 0 && __idx < size(), "span<T,N>[] index out of bounds");
322 _LIBCPP_ASSERT(__idx < size(), "span<T,N>[] index out of bounds");
305323 return __data[__idx];
306324 }
307325
308326 _LIBCPP_INLINE_VISIBILITY constexpr reference front() const noexcept
309327 {
310 static_assert(_Extent > 0, "span<T,N>[].front() on empty span");
328 _LIBCPP_ASSERT(!empty(), "span<T, N>::front() on empty span");
311329 return __data[0];
312330 }
313331
314332 _LIBCPP_INLINE_VISIBILITY constexpr reference back() const noexcept
315333 {
316 static_assert(_Extent > 0, "span<T,N>[].back() on empty span");
334 _LIBCPP_ASSERT(!empty(), "span<T, N>::back() on empty span");
317335 return __data[size()-1];
318336 }
319337
......@@ -322,25 +340,14 @@ public:
322340// [span.iter], span iterator support
323341 _LIBCPP_INLINE_VISIBILITY constexpr iterator begin() const noexcept { return iterator(data()); }
324342 _LIBCPP_INLINE_VISIBILITY constexpr iterator end() const noexcept { return iterator(data() + size()); }
325 _LIBCPP_INLINE_VISIBILITY constexpr const_iterator cbegin() const noexcept { return const_iterator(data()); }
326 _LIBCPP_INLINE_VISIBILITY constexpr const_iterator cend() const noexcept { return const_iterator(data() + size()); }
327343 _LIBCPP_INLINE_VISIBILITY constexpr reverse_iterator rbegin() const noexcept { return reverse_iterator(end()); }
328344 _LIBCPP_INLINE_VISIBILITY constexpr reverse_iterator rend() const noexcept { return reverse_iterator(begin()); }
329 _LIBCPP_INLINE_VISIBILITY constexpr const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator(cend()); }
330 _LIBCPP_INLINE_VISIBILITY constexpr const_reverse_iterator crend() const noexcept { return const_reverse_iterator(cbegin()); }
331
332 _LIBCPP_INLINE_VISIBILITY constexpr void swap(span &__other) noexcept
333 {
334 pointer __p = __data;
335 __data = __other.__data;
336 __other.__data = __p;
337 }
338345
339346 _LIBCPP_INLINE_VISIBILITY span<const byte, _Extent * sizeof(element_type)> __as_bytes() const noexcept
340 { return {reinterpret_cast<const byte *>(data()), size_bytes()}; }
347 { return span<const byte, _Extent * sizeof(element_type)>{reinterpret_cast<const byte *>(data()), size_bytes()}; }
341348
342349 _LIBCPP_INLINE_VISIBILITY span<byte, _Extent * sizeof(element_type)> __as_writable_bytes() const noexcept
343 { return {reinterpret_cast<byte *>(data()), size_bytes()}; }
350 { return span<byte, _Extent * sizeof(element_type)>{reinterpret_cast<byte *>(data()), size_bytes()}; }
344351
345352private:
346353 pointer __data;
......@@ -363,9 +370,7 @@ public:
363370 using reference = _Tp &;
364371 using const_reference = const _Tp &;
365372 using iterator = __wrap_iter<pointer>;
366 using const_iterator = __wrap_iter<const_pointer>;
367373 using reverse_iterator = _VSTD::reverse_iterator<iterator>;
368 using const_reverse_iterator = _VSTD::reverse_iterator<const_iterator>;
369374
370375 static constexpr size_type extent = dynamic_extent;
371376
......@@ -382,13 +387,15 @@ public:
382387 _LIBCPP_INLINE_VISIBILITY
383388 constexpr span(element_type (&__arr)[_Sz]) noexcept : __data{__arr}, __size{_Sz} {}
384389
385 template <size_t _Sz>
390 template <class _OtherElementType, size_t _Sz,
391 enable_if_t<is_convertible_v<_OtherElementType(*)[], element_type (*)[]>, nullptr_t> = nullptr>
386392 _LIBCPP_INLINE_VISIBILITY
387 constexpr span(array<value_type, _Sz>& __arr) noexcept : __data{__arr.data()}, __size{_Sz} {}
393 constexpr span(array<_OtherElementType, _Sz>& __arr) noexcept : __data{__arr.data()}, __size{_Sz} {}
388394
389 template <size_t _Sz>
395 template <class _OtherElementType, size_t _Sz,
396 enable_if_t<is_convertible_v<const _OtherElementType(*)[], element_type (*)[]>, nullptr_t> = nullptr>
390397 _LIBCPP_INLINE_VISIBILITY
391 constexpr span(const array<value_type, _Sz>& __arr) noexcept : __data{__arr.data()}, __size{_Sz} {}
398 constexpr span(const array<_OtherElementType, _Sz>& __arr) noexcept : __data{__arr.data()}, __size{_Sz} {}
392399
393400 template <class _Container>
394401 _LIBCPP_INLINE_VISIBILITY
......@@ -418,7 +425,7 @@ public:
418425 constexpr span<element_type, _Count> first() const noexcept
419426 {
420427 _LIBCPP_ASSERT(_Count <= size(), "Count out of range in span::first()");
421 return {data(), _Count};
428 return span<element_type, _Count>{data(), _Count};
422429 }
423430
424431 template <size_t _Count>
......@@ -426,7 +433,7 @@ public:
426433 constexpr span<element_type, _Count> last() const noexcept
427434 {
428435 _LIBCPP_ASSERT(_Count <= size(), "Count out of range in span::last()");
429 return {data() + size() - _Count, _Count};
436 return span<element_type, _Count>{data() + size() - _Count, _Count};
430437 }
431438
432439 _LIBCPP_INLINE_VISIBILITY
......@@ -445,11 +452,11 @@ public:
445452
446453 template <size_t _Offset, size_t _Count = dynamic_extent>
447454 _LIBCPP_INLINE_VISIBILITY
448 constexpr span<_Tp, dynamic_extent> subspan() const noexcept
455 constexpr span<element_type, _Count> subspan() const noexcept
449456 {
450457 _LIBCPP_ASSERT(_Offset <= size(), "Offset out of range in span::subspan()");
451 _LIBCPP_ASSERT(_Count == dynamic_extent || _Offset + _Count <= size(), "Count out of range in span::subspan()");
452 return {data() + _Offset, _Count == dynamic_extent ? size() - _Offset : _Count};
458 _LIBCPP_ASSERT(_Count == dynamic_extent || _Count <= size() - _Offset, "Offset + count out of range in span::subspan()");
459 return span<element_type, _Count>{data() + _Offset, _Count == dynamic_extent ? size() - _Offset : _Count};
453460 }
454461
455462 constexpr span<element_type, dynamic_extent>
......@@ -460,7 +467,7 @@ public:
460467 _LIBCPP_ASSERT(__count <= size() || __count == dynamic_extent, "count out of range in span::subspan(offset, count)");
461468 if (__count == dynamic_extent)
462469 return {data() + __offset, size() - __offset};
463 _LIBCPP_ASSERT(__offset <= size() - __count, "Offset + count out of range in span::subspan(offset, count)");
470 _LIBCPP_ASSERT(__count <= size() - __offset, "Offset + count out of range in span::subspan(offset, count)");
464471 return {data() + __offset, __count};
465472 }
466473
......@@ -470,7 +477,7 @@ public:
470477
471478 _LIBCPP_INLINE_VISIBILITY constexpr reference operator[](size_type __idx) const noexcept
472479 {
473 _LIBCPP_ASSERT(__idx >= 0 && __idx < size(), "span<T>[] index out of bounds");
480 _LIBCPP_ASSERT(__idx < size(), "span<T>[] index out of bounds");
474481 return __data[__idx];
475482 }
476483
......@@ -492,23 +499,8 @@ public:
492499// [span.iter], span iterator support
493500 _LIBCPP_INLINE_VISIBILITY constexpr iterator begin() const noexcept { return iterator(data()); }
494501 _LIBCPP_INLINE_VISIBILITY constexpr iterator end() const noexcept { return iterator(data() + size()); }
495 _LIBCPP_INLINE_VISIBILITY constexpr const_iterator cbegin() const noexcept { return const_iterator(data()); }
496 _LIBCPP_INLINE_VISIBILITY constexpr const_iterator cend() const noexcept { return const_iterator(data() + size()); }
497502 _LIBCPP_INLINE_VISIBILITY constexpr reverse_iterator rbegin() const noexcept { return reverse_iterator(end()); }
498503 _LIBCPP_INLINE_VISIBILITY constexpr reverse_iterator rend() const noexcept { return reverse_iterator(begin()); }
499 _LIBCPP_INLINE_VISIBILITY constexpr const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator(cend()); }
500 _LIBCPP_INLINE_VISIBILITY constexpr const_reverse_iterator crend() const noexcept { return const_reverse_iterator(cbegin()); }
501
502 _LIBCPP_INLINE_VISIBILITY constexpr void swap(span &__other) noexcept
503 {
504 pointer __p = __data;
505 __data = __other.__data;
506 __other.__data = __p;
507
508 size_type __sz = __size;
509 __size = __other.__size;
510 __other.__size = __sz;
511 }
512504
513505 _LIBCPP_INLINE_VISIBILITY span<const byte, dynamic_extent> __as_bytes() const noexcept
514506 { return {reinterpret_cast<const byte *>(data()), size_bytes()}; }
......@@ -521,34 +513,6 @@ private:
521513 size_type __size;
522514};
523515
524// tuple interface
525template <class _Tp, size_t _Size>
526struct _LIBCPP_TEMPLATE_VIS tuple_size<span<_Tp, _Size>>
527 : public integral_constant<size_t, _Size> {};
528
529template <class _Tp>
530struct _LIBCPP_TEMPLATE_VIS tuple_size<span<_Tp, dynamic_extent>>; // declared but not defined
531
532
533template <size_t _Ip, class _Tp, size_t _Size>
534struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, span<_Tp, _Size>>
535{
536 static_assert( dynamic_extent != _Size, "std::tuple_element<> not supported for std::span<T, dynamic_extent>");
537 static_assert(_Ip < _Size, "Index out of bounds in std::tuple_element<> (std::span)");
538 typedef _Tp type;
539};
540
541template <size_t _Ip, class _Tp, size_t _Size>
542_LIBCPP_INLINE_VISIBILITY constexpr
543_Tp&
544get(span<_Tp, _Size> __s) noexcept
545{
546 static_assert( dynamic_extent != _Size, "std::get<> not supported for std::span<T, dynamic_extent>");
547 static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::span)");
548 return __s[_Ip];
549}
550
551
552516// as_bytes & as_writable_bytes
553517template <class _Tp, size_t _Extent>
554518_LIBCPP_INLINE_VISIBILITY
......@@ -562,12 +526,6 @@ auto as_writable_bytes(span<_Tp, _Extent> __s) noexcept
562526-> enable_if_t<!is_const_v<_Tp>, decltype(__s.__as_writable_bytes())>
563527{ return __s.__as_writable_bytes(); }
564528
565template <class _Tp, size_t _Extent>
566_LIBCPP_INLINE_VISIBILITY
567constexpr void swap(span<_Tp, _Extent> &__lhs, span<_Tp, _Extent> &__rhs) noexcept
568{ __lhs.swap(__rhs); }
569
570
571529// Deduction guides
572530template<class _Tp, size_t _Sz>
573531 span(_Tp (&)[_Sz]) -> span<_Tp, _Sz>;
lib/libcxx/include/stddef.h+1-7
......@@ -31,7 +31,7 @@ Types:
3131
3232 ptrdiff_t
3333 size_t
34 max_align_t
34 max_align_t // C++11
3535 nullptr_t
3636
3737*/
......@@ -51,12 +51,6 @@ extern "C++" {
5151using std::nullptr_t;
5252}
5353
54// Re-use the compiler's <stddef.h> max_align_t where possible.
55#if !defined(__CLANG_MAX_ALIGN_T_DEFINED) && !defined(_GCC_MAX_ALIGN_T) && \
56 !defined(__DEFINED_max_align_t) && !defined(__NetBSD__)
57typedef long double max_align_t;
58#endif
59
6054#endif
6155
6256#endif // _LIBCPP_STDDEF_H
lib/libcxx/include/stdexcept+7
......@@ -129,6 +129,7 @@ public:
129129 _LIBCPP_INLINE_VISIBILITY explicit domain_error(const char* __s) : logic_error(__s) {}
130130
131131#ifndef _LIBCPP_ABI_VCRUNTIME
132 domain_error(const domain_error&) _NOEXCEPT = default;
132133 virtual ~domain_error() _NOEXCEPT;
133134#endif
134135};
......@@ -141,6 +142,7 @@ public:
141142 _LIBCPP_INLINE_VISIBILITY explicit invalid_argument(const char* __s) : logic_error(__s) {}
142143
143144#ifndef _LIBCPP_ABI_VCRUNTIME
145 invalid_argument(const invalid_argument&) _NOEXCEPT = default;
144146 virtual ~invalid_argument() _NOEXCEPT;
145147#endif
146148};
......@@ -152,6 +154,7 @@ public:
152154 _LIBCPP_INLINE_VISIBILITY explicit length_error(const string& __s) : logic_error(__s) {}
153155 _LIBCPP_INLINE_VISIBILITY explicit length_error(const char* __s) : logic_error(__s) {}
154156#ifndef _LIBCPP_ABI_VCRUNTIME
157 length_error(const length_error&) _NOEXCEPT = default;
155158 virtual ~length_error() _NOEXCEPT;
156159#endif
157160};
......@@ -164,6 +167,7 @@ public:
164167 _LIBCPP_INLINE_VISIBILITY explicit out_of_range(const char* __s) : logic_error(__s) {}
165168
166169#ifndef _LIBCPP_ABI_VCRUNTIME
170 out_of_range(const out_of_range&) _NOEXCEPT = default;
167171 virtual ~out_of_range() _NOEXCEPT;
168172#endif
169173};
......@@ -176,6 +180,7 @@ public:
176180 _LIBCPP_INLINE_VISIBILITY explicit range_error(const char* __s) : runtime_error(__s) {}
177181
178182#ifndef _LIBCPP_ABI_VCRUNTIME
183 range_error(const range_error&) _NOEXCEPT = default;
179184 virtual ~range_error() _NOEXCEPT;
180185#endif
181186};
......@@ -188,6 +193,7 @@ public:
188193 _LIBCPP_INLINE_VISIBILITY explicit overflow_error(const char* __s) : runtime_error(__s) {}
189194
190195#ifndef _LIBCPP_ABI_VCRUNTIME
196 overflow_error(const overflow_error&) _NOEXCEPT = default;
191197 virtual ~overflow_error() _NOEXCEPT;
192198#endif
193199};
......@@ -200,6 +206,7 @@ public:
200206 _LIBCPP_INLINE_VISIBILITY explicit underflow_error(const char* __s) : runtime_error(__s) {}
201207
202208#ifndef _LIBCPP_ABI_VCRUNTIME
209 underflow_error(const underflow_error&) _NOEXCEPT = default;
203210 virtual ~underflow_error() _NOEXCEPT;
204211#endif
205212};
lib/libcxx/include/stdlib.h+58-6
......@@ -7,16 +7,12 @@
77//
88//===----------------------------------------------------------------------===//
99
10#if defined(__need_malloc_and_calloc) || defined(_LIBCPP_STDLIB_INCLUDE_NEXT)
10#if defined(__need_malloc_and_calloc)
1111
1212#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1313#pragma GCC system_header
1414#endif
1515
16#if defined(_LIBCPP_STDLIB_INCLUDE_NEXT)
17#undef _LIBCPP_STDLIB_INCLUDE_NEXT
18#endif
19
2016#include_next <stdlib.h>
2117
2218#elif !defined(_LIBCPP_STDLIB_H)
......@@ -97,7 +93,63 @@ void *aligned_alloc(size_t alignment, size_t size); // C11
9793#include_next <stdlib.h>
9894
9995#ifdef __cplusplus
100#include <math.h>
96extern "C++" {
97// abs
98
99#undef abs
100#undef labs
101#ifndef _LIBCPP_HAS_NO_LONG_LONG
102#undef llabs
103#endif
104
105// MSVCRT already has the correct prototype in <stdlib.h> if __cplusplus is defined
106#if !defined(_LIBCPP_MSVCRT) && !defined(__sun__) && !defined(_AIX)
107inline _LIBCPP_INLINE_VISIBILITY long abs(long __x) _NOEXCEPT {
108 return __builtin_labs(__x);
109}
110#ifndef _LIBCPP_HAS_NO_LONG_LONG
111inline _LIBCPP_INLINE_VISIBILITY long long abs(long long __x) _NOEXCEPT {
112 return __builtin_llabs(__x);
113}
114#endif // _LIBCPP_HAS_NO_LONG_LONG
115#endif // !defined(_LIBCPP_MSVCRT) && !defined(__sun__) && !defined(_AIX)
116
117#if !(defined(_AIX) || defined(__sun__))
118inline _LIBCPP_INLINE_VISIBILITY float abs(float __lcpp_x) _NOEXCEPT {
119 return __builtin_fabsf(__lcpp_x); // Use builtins to prevent needing math.h
120}
121
122inline _LIBCPP_INLINE_VISIBILITY double abs(double __lcpp_x) _NOEXCEPT {
123 return __builtin_fabs(__lcpp_x);
124}
125
126inline _LIBCPP_INLINE_VISIBILITY long double
127abs(long double __lcpp_x) _NOEXCEPT {
128 return __builtin_fabsl(__lcpp_x);
129}
130#endif // !(defined(_AIX) || defined(__sun__))
131
132// div
133
134#undef div
135#undef ldiv
136#ifndef _LIBCPP_HAS_NO_LONG_LONG
137#undef lldiv
138#endif
139
140// MSVCRT already has the correct prototype in <stdlib.h> if __cplusplus is defined
141#if !defined(_LIBCPP_MSVCRT) && !defined(__sun__) && !defined(_AIX)
142inline _LIBCPP_INLINE_VISIBILITY ldiv_t div(long __x, long __y) _NOEXCEPT {
143 return ::ldiv(__x, __y);
144}
145#ifndef _LIBCPP_HAS_NO_LONG_LONG
146inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x,
147 long long __y) _NOEXCEPT {
148 return ::lldiv(__x, __y);
149}
150#endif // _LIBCPP_HAS_NO_LONG_LONG
151#endif // _LIBCPP_MSVCRT / __sun__ / _AIX
152} // extern "C++"
101153#endif // __cplusplus
102154
103155#endif // _LIBCPP_STDLIB_H
lib/libcxx/include/string+313-185
......@@ -437,9 +437,11 @@ basic_istream<charT, traits>&
437437getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
438438
439439template<class charT, class traits, class Allocator, class U>
440void erase(basic_string<charT, traits, Allocator>& c, const U& value); // C++20
440typename basic_string<charT, traits, Allocator>::size_type
441erase(basic_string<charT, traits, Allocator>& c, const U& value); // C++20
441442template<class charT, class traits, class Allocator, class Predicate>
442void erase_if(basic_string<charT, traits, Allocator>& c, Predicate pred); // C++20
443typename basic_string<charT, traits, Allocator>::size_type
444erase_if(basic_string<charT, traits, Allocator>& c, Predicate pred); // C++20
443445
444446typedef basic_string<char> string;
445447typedef basic_string<wchar_t> wstring;
......@@ -643,9 +645,10 @@ struct __libcpp_string_gets_noexcept_iterator
643645 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value || __libcpp_string_gets_noexcept_iterator_impl<_Iter>::value) {};
644646
645647template <class _CharT, class _Traits, class _Tp>
646struct __can_be_converted_to_string_view : public _LIBCPP_BOOL_CONSTANT(
647 ( is_convertible<const _Tp&, basic_string_view<_CharT, _Traits> >::value &&
648 !is_convertible<const _Tp&, const _CharT*>::value)) {};
648struct __can_be_converted_to_string_view : public _BoolConstant<
649 is_convertible<const _Tp&, basic_string_view<_CharT, _Traits> >::value &&
650 !is_convertible<const _Tp&, const _CharT*>::value
651 > {};
649652
650653#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
651654
......@@ -688,13 +691,8 @@ public:
688691 static_assert(( is_same<typename allocator_type::value_type, value_type>::value),
689692 "Allocator::value_type must be same type as value_type");
690693
691#if defined(_LIBCPP_RAW_ITERATORS)
692 typedef pointer iterator;
693 typedef const_pointer const_iterator;
694#else // defined(_LIBCPP_RAW_ITERATORS)
695694 typedef __wrap_iter<pointer> iterator;
696695 typedef __wrap_iter<const_pointer> const_iterator;
697#endif // defined(_LIBCPP_RAW_ITERATORS)
698696 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
699697 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
700698
......@@ -784,6 +782,7 @@ private:
784782 __compressed_pair<__rep, allocator_type> __r_;
785783
786784public:
785 _LIBCPP_FUNC_VIS
787786 static const size_type npos = -1;
788787
789788 _LIBCPP_INLINE_VISIBILITY basic_string()
......@@ -812,7 +811,7 @@ public:
812811 basic_string(basic_string&& __str, const allocator_type& __a);
813812#endif // _LIBCPP_CXX03_LANG
814813
815 template <class = typename enable_if<__is_allocator<_Allocator>::value, nullptr_t>::type>
814 template <class = _EnableIf<__is_allocator<_Allocator>::value, nullptr_t> >
816815 _LIBCPP_INLINE_VISIBILITY
817816 basic_string(const _CharT* __s) : __r_(__default_init_tag(), __default_init_tag()) {
818817 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr");
......@@ -822,7 +821,7 @@ public:
822821# endif
823822 }
824823
825 template <class = typename enable_if<__is_allocator<_Allocator>::value, nullptr_t>::type>
824 template <class = _EnableIf<__is_allocator<_Allocator>::value, nullptr_t> >
826825 _LIBCPP_INLINE_VISIBILITY
827826 basic_string(const _CharT* __s, const _Allocator& __a);
828827
......@@ -833,7 +832,7 @@ public:
833832 _LIBCPP_INLINE_VISIBILITY
834833 basic_string(size_type __n, _CharT __c);
835834
836 template <class = typename enable_if<__is_allocator<_Allocator>::value, nullptr_t>::type>
835 template <class = _EnableIf<__is_allocator<_Allocator>::value, nullptr_t> >
837836 _LIBCPP_INLINE_VISIBILITY
838837 basic_string(size_type __n, _CharT __c, const _Allocator& __a);
839838
......@@ -843,23 +842,24 @@ public:
843842 basic_string(const basic_string& __str, size_type __pos,
844843 const _Allocator& __a = _Allocator());
845844
846 template<class _Tp, class = typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type>
845 template<class _Tp, class = _EnableIf<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value> >
847846 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
848847 basic_string(const _Tp& __t, size_type __pos, size_type __n,
849 const allocator_type& __a = allocator_type());
848 const allocator_type& __a = allocator_type());
850849
851 template<class _Tp, class = typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type>
850 template<class _Tp, class = _EnableIf<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value &&
851 !__is_same_uncvref<_Tp, basic_string>::value> >
852852 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
853853 explicit basic_string(const _Tp& __t);
854854
855 template<class _Tp, class = typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type>
855 template<class _Tp, class = _EnableIf<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value> >
856856 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
857857 explicit basic_string(const _Tp& __t, const allocator_type& __a);
858858
859 template<class _InputIterator, class = typename enable_if<__is_cpp17_input_iterator<_InputIterator>::value>::type>
859 template<class _InputIterator, class = _EnableIf<__is_cpp17_input_iterator<_InputIterator>::value> >
860860 _LIBCPP_INLINE_VISIBILITY
861861 basic_string(_InputIterator __first, _InputIterator __last);
862 template<class _InputIterator, class = typename enable_if<__is_cpp17_input_iterator<_InputIterator>::value>::type>
862 template<class _InputIterator, class = _EnableIf<__is_cpp17_input_iterator<_InputIterator>::value> >
863863 _LIBCPP_INLINE_VISIBILITY
864864 basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a);
865865#ifndef _LIBCPP_CXX03_LANG
......@@ -876,7 +876,7 @@ public:
876876
877877 basic_string& operator=(const basic_string& __str);
878878
879 template <class _Tp, class = typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type>
879 template <class _Tp, class = _EnableIf<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value> >
880880 basic_string& operator=(const _Tp& __t)
881881 {__self_view __sv = __t; return assign(__sv);}
882882
......@@ -976,11 +976,12 @@ public:
976976
977977 template <class _Tp>
978978 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
979 typename enable_if
979 _EnableIf
980980 <
981 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
981 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
982 && !__is_same_uncvref<_Tp, basic_string >::value,
982983 basic_string&
983 >::type
984 >
984985 operator+=(const _Tp& __t) {__self_view __sv = __t; return append(__sv);}
985986 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const value_type* __s) {return append(__s);}
986987 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(value_type __c) {push_back(__c); return *this;}
......@@ -993,21 +994,22 @@ public:
993994
994995 template <class _Tp>
995996 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
996 typename enable_if
997 <
998 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
997 _EnableIf<
998 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
999 && !__is_same_uncvref<_Tp, basic_string>::value,
9991000 basic_string&
1000 >::type
1001 >
10011002 append(const _Tp& __t) { __self_view __sv = __t; return append(__sv.data(), __sv.size()); }
10021003 basic_string& append(const basic_string& __str, size_type __pos, size_type __n=npos);
10031004
10041005 template <class _Tp>
10051006 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1006 typename enable_if
1007 _EnableIf
10071008 <
1008 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1009 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
1010 && !__is_same_uncvref<_Tp, basic_string>::value,
10091011 basic_string&
1010 >::type
1012 >
10111013 append(const _Tp& __t, size_type __pos, size_type __n=npos);
10121014 basic_string& append(const value_type* __s, size_type __n);
10131015 basic_string& append(const value_type* __s);
......@@ -1021,12 +1023,12 @@ public:
10211023 basic_string& __append_forward_unsafe(_ForwardIterator, _ForwardIterator);
10221024 template<class _InputIterator>
10231025 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1024 typename enable_if
1026 _EnableIf
10251027 <
10261028 __is_exactly_cpp17_input_iterator<_InputIterator>::value
10271029 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
10281030 basic_string&
1029 >::type
1031 >
10301032 _LIBCPP_INLINE_VISIBILITY
10311033 append(_InputIterator __first, _InputIterator __last) {
10321034 const basic_string __temp (__first, __last, __alloc());
......@@ -1035,12 +1037,12 @@ public:
10351037 }
10361038 template<class _ForwardIterator>
10371039 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1038 typename enable_if
1040 _EnableIf
10391041 <
10401042 __is_cpp17_forward_iterator<_ForwardIterator>::value
10411043 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
10421044 basic_string&
1043 >::type
1045 >
10441046 _LIBCPP_INLINE_VISIBILITY
10451047 append(_ForwardIterator __first, _ForwardIterator __last) {
10461048 return __append_forward_unsafe(__first, __last);
......@@ -1061,11 +1063,11 @@ public:
10611063
10621064 template <class _Tp>
10631065 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1064 typename enable_if
1066 _EnableIf
10651067 <
10661068 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
10671069 basic_string&
1068 >::type
1070 >
10691071 assign(const _Tp & __t) { __self_view __sv = __t; return assign(__sv.data(), __sv.size()); }
10701072 _LIBCPP_INLINE_VISIBILITY
10711073 basic_string& assign(const basic_string& __str) { return *this = __str; }
......@@ -1078,32 +1080,33 @@ public:
10781080 basic_string& assign(const basic_string& __str, size_type __pos, size_type __n=npos);
10791081 template <class _Tp>
10801082 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1081 typename enable_if
1083 _EnableIf
10821084 <
1083 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1085 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
1086 && !__is_same_uncvref<_Tp, basic_string>::value,
10841087 basic_string&
1085 >::type
1088 >
10861089 assign(const _Tp & __t, size_type __pos, size_type __n=npos);
10871090 basic_string& assign(const value_type* __s, size_type __n);
10881091 basic_string& assign(const value_type* __s);
10891092 basic_string& assign(size_type __n, value_type __c);
10901093 template<class _InputIterator>
10911094 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1092 typename enable_if
1095 _EnableIf
10931096 <
10941097 __is_exactly_cpp17_input_iterator<_InputIterator>::value
10951098 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
10961099 basic_string&
1097 >::type
1100 >
10981101 assign(_InputIterator __first, _InputIterator __last);
10991102 template<class _ForwardIterator>
11001103 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1101 typename enable_if
1104 _EnableIf
11021105 <
11031106 __is_cpp17_forward_iterator<_ForwardIterator>::value
11041107 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
11051108 basic_string&
1106 >::type
1109 >
11071110 assign(_ForwardIterator __first, _ForwardIterator __last);
11081111#ifndef _LIBCPP_CXX03_LANG
11091112 _LIBCPP_INLINE_VISIBILITY
......@@ -1115,21 +1118,21 @@ public:
11151118
11161119 template <class _Tp>
11171120 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1118 typename enable_if
1121 _EnableIf
11191122 <
11201123 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
11211124 basic_string&
1122 >::type
1125 >
11231126 insert(size_type __pos1, const _Tp& __t)
11241127 { __self_view __sv = __t; return insert(__pos1, __sv.data(), __sv.size()); }
11251128
11261129 template <class _Tp>
11271130 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1128 typename enable_if
1131 _EnableIf
11291132 <
1130 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1133 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value,
11311134 basic_string&
1132 >::type
1135 >
11331136 insert(size_type __pos1, const _Tp& __t, size_type __pos2, size_type __n=npos);
11341137 basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n=npos);
11351138 basic_string& insert(size_type __pos, const value_type* __s, size_type __n);
......@@ -1140,21 +1143,21 @@ public:
11401143 iterator insert(const_iterator __pos, size_type __n, value_type __c);
11411144 template<class _InputIterator>
11421145 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1143 typename enable_if
1146 _EnableIf
11441147 <
11451148 __is_exactly_cpp17_input_iterator<_InputIterator>::value
11461149 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
11471150 iterator
1148 >::type
1151 >
11491152 insert(const_iterator __pos, _InputIterator __first, _InputIterator __last);
11501153 template<class _ForwardIterator>
11511154 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1152 typename enable_if
1155 _EnableIf
11531156 <
11541157 __is_cpp17_forward_iterator<_ForwardIterator>::value
11551158 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
11561159 iterator
1157 >::type
1160 >
11581161 insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last);
11591162#ifndef _LIBCPP_CXX03_LANG
11601163 _LIBCPP_INLINE_VISIBILITY
......@@ -1173,20 +1176,20 @@ public:
11731176
11741177 template <class _Tp>
11751178 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1176 typename enable_if
1179 _EnableIf
11771180 <
11781181 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
11791182 basic_string&
1180 >::type
1183 >
11811184 replace(size_type __pos1, size_type __n1, const _Tp& __t) { __self_view __sv = __t; return replace(__pos1, __n1, __sv.data(), __sv.size()); }
11821185 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos);
11831186 template <class _Tp>
11841187 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1185 typename enable_if
1188 _EnableIf
11861189 <
1187 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1190 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value,
11881191 basic_string&
1189 >::type
1192 >
11901193 replace(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2=npos);
11911194 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2);
11921195 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s);
......@@ -1196,11 +1199,11 @@ public:
11961199
11971200 template <class _Tp>
11981201 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1199 typename enable_if
1202 _EnableIf
12001203 <
12011204 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
12021205 basic_string&
1203 >::type
1206 >
12041207 replace(const_iterator __i1, const_iterator __i2, const _Tp& __t) { __self_view __sv = __t; return replace(__i1 - begin(), __i2 - __i1, __sv); }
12051208
12061209 _LIBCPP_INLINE_VISIBILITY
......@@ -1211,11 +1214,11 @@ public:
12111214 basic_string& replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c);
12121215 template<class _InputIterator>
12131216 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1214 typename enable_if
1217 _EnableIf
12151218 <
12161219 __is_cpp17_input_iterator<_InputIterator>::value,
12171220 basic_string&
1218 >::type
1221 >
12191222 replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2);
12201223#ifndef _LIBCPP_CXX03_LANG
12211224 _LIBCPP_INLINE_VISIBILITY
......@@ -1253,11 +1256,11 @@ public:
12531256
12541257 template <class _Tp>
12551258 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1256 typename enable_if
1259 _EnableIf
12571260 <
12581261 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
12591262 size_type
1260 >::type
1263 >
12611264 find(const _Tp& __t, size_type __pos = 0) const;
12621265 size_type find(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
12631266 _LIBCPP_INLINE_VISIBILITY
......@@ -1269,11 +1272,11 @@ public:
12691272
12701273 template <class _Tp>
12711274 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1272 typename enable_if
1275 _EnableIf
12731276 <
12741277 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
12751278 size_type
1276 >::type
1279 >
12771280 rfind(const _Tp& __t, size_type __pos = npos) const;
12781281 size_type rfind(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
12791282 _LIBCPP_INLINE_VISIBILITY
......@@ -1285,11 +1288,11 @@ public:
12851288
12861289 template <class _Tp>
12871290 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1288 typename enable_if
1291 _EnableIf
12891292 <
12901293 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
12911294 size_type
1292 >::type
1295 >
12931296 find_first_of(const _Tp& __t, size_type __pos = 0) const;
12941297 size_type find_first_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
12951298 _LIBCPP_INLINE_VISIBILITY
......@@ -1302,11 +1305,11 @@ public:
13021305
13031306 template <class _Tp>
13041307 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1305 typename enable_if
1308 _EnableIf
13061309 <
13071310 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
13081311 size_type
1309 >::type
1312 >
13101313 find_last_of(const _Tp& __t, size_type __pos = npos) const;
13111314 size_type find_last_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
13121315 _LIBCPP_INLINE_VISIBILITY
......@@ -1319,11 +1322,11 @@ public:
13191322
13201323 template <class _Tp>
13211324 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1322 typename enable_if
1325 _EnableIf
13231326 <
13241327 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
13251328 size_type
1326 >::type
1329 >
13271330 find_first_not_of(const _Tp &__t, size_type __pos = 0) const;
13281331 size_type find_first_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
13291332 _LIBCPP_INLINE_VISIBILITY
......@@ -1336,11 +1339,11 @@ public:
13361339
13371340 template <class _Tp>
13381341 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1339 typename enable_if
1342 _EnableIf
13401343 <
13411344 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
13421345 size_type
1343 >::type
1346 >
13441347 find_last_not_of(const _Tp& __t, size_type __pos = npos) const;
13451348 size_type find_last_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
13461349 _LIBCPP_INLINE_VISIBILITY
......@@ -1353,20 +1356,20 @@ public:
13531356
13541357 template <class _Tp>
13551358 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1356 typename enable_if
1359 _EnableIf
13571360 <
13581361 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
13591362 int
1360 >::type
1363 >
13611364 compare(const _Tp &__t) const;
13621365
13631366 template <class _Tp>
13641367 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1365 typename enable_if
1368 _EnableIf
13661369 <
13671370 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
13681371 int
1369 >::type
1372 >
13701373 compare(size_type __pos1, size_type __n1, const _Tp& __t) const;
13711374
13721375 _LIBCPP_INLINE_VISIBILITY
......@@ -1375,11 +1378,11 @@ public:
13751378
13761379 template <class _Tp>
13771380 inline _LIBCPP_INLINE_VISIBILITY
1378 typename enable_if
1381 _EnableIf
13791382 <
1380 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1383 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value,
13811384 int
1382 >::type
1385 >
13831386 compare(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2=npos) const;
13841387 int compare(const value_type* __s) const _NOEXCEPT;
13851388 int compare(size_type __pos1, size_type __n1, const value_type* __s) const;
......@@ -1543,22 +1546,30 @@ private:
15431546 inline
15441547 void __init(size_type __n, value_type __c);
15451548
1549 // Slow path for the (inlined) copy constructor for 'long' strings.
1550 // Always externally instantiated and not inlined.
1551 // Requires that __s is zero terminated.
1552 // The main reason for this function to exist is because for unstable, we
1553 // want to allow inlining of the copy constructor. However, we don't want
1554 // to call the __init() functions as those are marked as inline which may
1555 // result in over-aggressive inlining by the compiler, where our aim is
1556 // to only inline the fast path code directly in the ctor.
1557 void __init_copy_ctor_external(const value_type* __s, size_type __sz);
1558
15461559 template <class _InputIterator>
15471560 inline
1548 typename enable_if
1561 _EnableIf
15491562 <
1550 __is_exactly_cpp17_input_iterator<_InputIterator>::value,
1551 void
1552 >::type
1563 __is_exactly_cpp17_input_iterator<_InputIterator>::value
1564 >
15531565 __init(_InputIterator __first, _InputIterator __last);
15541566
15551567 template <class _ForwardIterator>
15561568 inline
1557 typename enable_if
1569 _EnableIf
15581570 <
1559 __is_cpp17_forward_iterator<_ForwardIterator>::value,
1560 void
1561 >::type
1571 __is_cpp17_forward_iterator<_ForwardIterator>::value
1572 >
15621573 __init(_ForwardIterator __first, _ForwardIterator __last);
15631574
15641575 void __grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
......@@ -1567,9 +1578,19 @@ private:
15671578 size_type __n_copy, size_type __n_del,
15681579 size_type __n_add, const value_type* __p_new_stuff);
15691580
1581 // __assign_no_alias is invoked for assignment operations where we
1582 // have proof that the input does not alias the current instance.
1583 // For example, operator=(basic_string) performs a 'self' check.
1584 template <bool __is_short>
1585 basic_string& __assign_no_alias(const value_type* __s, size_type __n);
1586
15701587 _LIBCPP_INLINE_VISIBILITY
15711588 void __erase_to_end(size_type __pos);
15721589
1590 // __erase_external_with_move is invoked for erase() invocations where
1591 // `n ~= npos`, likely requiring memory moves on the string data.
1592 void __erase_external_with_move(size_type __pos, size_type __n);
1593
15731594 _LIBCPP_INLINE_VISIBILITY
15741595 void __copy_assign_alloc(const basic_string& __str)
15751596 {__copy_assign_alloc(__str, integral_constant<bool,
......@@ -1638,6 +1659,19 @@ private:
16381659 _NOEXCEPT
16391660 {}
16401661
1662 basic_string& __assign_external(const value_type* __s);
1663 basic_string& __assign_external(const value_type* __s, size_type __n);
1664
1665 // Assigns the value in __s, guaranteed to be __n < __min_cap in length.
1666 inline basic_string& __assign_short(const value_type* __s, size_type __n) {
1667 pointer __p = __is_long()
1668 ? (__set_long_size(__n), __get_long_pointer())
1669 : (__set_short_size(__n), __get_short_pointer());
1670 traits_type::move(_VSTD::__to_address(__p), __s, __n);
1671 traits_type::assign(__p[__n], value_type());
1672 return *this;
1673 }
1674
16411675 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
16421676 _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(size_type);
16431677
......@@ -1648,12 +1682,23 @@ private:
16481682 friend basic_string operator+<>(const basic_string&, value_type);
16491683};
16501684
1685// These declarations must appear before any functions are implicitly used
1686// so that they have the correct visibility specifier.
1687#ifdef _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION
1688_LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, char)
1689_LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, wchar_t)
1690#else
1691_LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, char)
1692_LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, wchar_t)
1693#endif
1694
1695
16511696#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
16521697template<class _InputIterator,
16531698 class _CharT = typename iterator_traits<_InputIterator>::value_type,
16541699 class _Allocator = allocator<_CharT>,
1655 class = typename enable_if<__is_cpp17_input_iterator<_InputIterator>::value, void>::type,
1656 class = typename enable_if<__is_allocator<_Allocator>::value, void>::type
1700 class = _EnableIf<__is_cpp17_input_iterator<_InputIterator>::value>,
1701 class = _EnableIf<__is_allocator<_Allocator>::value>
16571702 >
16581703basic_string(_InputIterator, _InputIterator, _Allocator = _Allocator())
16591704 -> basic_string<_CharT, char_traits<_CharT>, _Allocator>;
......@@ -1661,7 +1706,7 @@ basic_string(_InputIterator, _InputIterator, _Allocator = _Allocator())
16611706template<class _CharT,
16621707 class _Traits,
16631708 class _Allocator = allocator<_CharT>,
1664 class = typename enable_if<__is_allocator<_Allocator>::value, void>::type
1709 class = _EnableIf<__is_allocator<_Allocator>::value>
16651710 >
16661711explicit basic_string(basic_string_view<_CharT, _Traits>, const _Allocator& = _Allocator())
16671712 -> basic_string<_CharT, _Traits, _Allocator>;
......@@ -1669,14 +1714,13 @@ explicit basic_string(basic_string_view<_CharT, _Traits>, const _Allocator& = _A
16691714template<class _CharT,
16701715 class _Traits,
16711716 class _Allocator = allocator<_CharT>,
1672 class = typename enable_if<__is_allocator<_Allocator>::value, void>::type,
1717 class = _EnableIf<__is_allocator<_Allocator>::value>,
16731718 class _Sz = typename allocator_traits<_Allocator>::size_type
16741719 >
16751720basic_string(basic_string_view<_CharT, _Traits>, _Sz, _Sz, const _Allocator& = _Allocator())
16761721 -> basic_string<_CharT, _Traits, _Allocator>;
16771722#endif
16781723
1679
16801724template <class _CharT, class _Traits, class _Allocator>
16811725inline
16821726void
......@@ -1837,7 +1881,9 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __st
18371881 if (!__str.__is_long())
18381882 __r_.first().__r = __str.__r_.first().__r;
18391883 else
1840 __init(_VSTD::__to_address(__str.__get_long_pointer()), __str.__get_long_size());
1884 __init_copy_ctor_external(_VSTD::__to_address(__str.__get_long_pointer()),
1885 __str.__get_long_size());
1886
18411887#if _LIBCPP_DEBUG_LEVEL >= 2
18421888 __get_db()->__insert_c(this);
18431889#endif
......@@ -1851,12 +1897,32 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(
18511897 if (!__str.__is_long())
18521898 __r_.first().__r = __str.__r_.first().__r;
18531899 else
1854 __init(_VSTD::__to_address(__str.__get_long_pointer()), __str.__get_long_size());
1900 __init_copy_ctor_external(_VSTD::__to_address(__str.__get_long_pointer()),
1901 __str.__get_long_size());
18551902#if _LIBCPP_DEBUG_LEVEL >= 2
18561903 __get_db()->__insert_c(this);
18571904#endif
18581905}
18591906
1907template <class _CharT, class _Traits, class _Allocator>
1908void basic_string<_CharT, _Traits, _Allocator>::__init_copy_ctor_external(
1909 const value_type* __s, size_type __sz) {
1910 pointer __p;
1911 if (__sz < __min_cap) {
1912 __p = __get_short_pointer();
1913 __set_short_size(__sz);
1914 } else {
1915 if (__sz > max_size())
1916 this->__throw_length_error();
1917 size_t __cap = __recommend(__sz);
1918 __p = __alloc_traits::allocate(__alloc(), __cap + 1);
1919 __set_long_pointer(__p);
1920 __set_long_cap(__cap + 1);
1921 __set_long_size(__sz);
1922 }
1923 traits_type::copy(_VSTD::__to_address(__p), __s, __sz + 1);
1924}
1925
18601926#ifndef _LIBCPP_CXX03_LANG
18611927
18621928template <class _CharT, class _Traits, class _Allocator>
......@@ -2014,11 +2080,10 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t, const _
20142080
20152081template <class _CharT, class _Traits, class _Allocator>
20162082template <class _InputIterator>
2017typename enable_if
2083_EnableIf
20182084<
2019 __is_exactly_cpp17_input_iterator<_InputIterator>::value,
2020 void
2021>::type
2085 __is_exactly_cpp17_input_iterator<_InputIterator>::value
2086>
20222087basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last)
20232088{
20242089 __zero();
......@@ -2041,11 +2106,10 @@ basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _Input
20412106
20422107template <class _CharT, class _Traits, class _Allocator>
20432108template <class _ForwardIterator>
2044typename enable_if
2109_EnableIf
20452110<
2046 __is_cpp17_forward_iterator<_ForwardIterator>::value,
2047 void
2048>::type
2111 __is_cpp17_forward_iterator<_ForwardIterator>::value
2112>
20492113basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last)
20502114{
20512115 size_type __sz = static_cast<size_type>(_VSTD::distance(__first, __last));
......@@ -2197,26 +2261,51 @@ basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_t
21972261
21982262// assign
21992263
2264template <class _CharT, class _Traits, class _Allocator>
2265template <bool __is_short>
2266basic_string<_CharT, _Traits, _Allocator>&
2267basic_string<_CharT, _Traits, _Allocator>::__assign_no_alias(
2268 const value_type* __s, size_type __n) {
2269 size_type __cap = __is_short ? __min_cap : __get_long_cap();
2270 if (__n < __cap) {
2271 pointer __p = __is_short ? __get_short_pointer() : __get_long_pointer();
2272 __is_short ? __set_short_size(__n) : __set_long_size(__n);
2273 traits_type::copy(_VSTD::__to_address(__p), __s, __n);
2274 traits_type::assign(__p[__n], value_type());
2275 __invalidate_iterators_past(__n);
2276 } else {
2277 size_type __sz = __is_short ? __get_short_size() : __get_long_size();
2278 __grow_by_and_replace(__cap - 1, __n - __cap + 1, __sz, 0, __sz, __n, __s);
2279 }
2280 return *this;
2281}
2282
2283template <class _CharT, class _Traits, class _Allocator>
2284basic_string<_CharT, _Traits, _Allocator>&
2285basic_string<_CharT, _Traits, _Allocator>::__assign_external(
2286 const value_type* __s, size_type __n) {
2287 size_type __cap = capacity();
2288 if (__cap >= __n) {
2289 value_type* __p = _VSTD::__to_address(__get_pointer());
2290 traits_type::move(__p, __s, __n);
2291 traits_type::assign(__p[__n], value_type());
2292 __set_size(__n);
2293 __invalidate_iterators_past(__n);
2294 } else {
2295 size_type __sz = size();
2296 __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s);
2297 }
2298 return *this;
2299}
2300
22002301template <class _CharT, class _Traits, class _Allocator>
22012302basic_string<_CharT, _Traits, _Allocator>&
22022303basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n)
22032304{
22042305 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr");
2205 size_type __cap = capacity();
2206 if (__cap >= __n)
2207 {
2208 value_type* __p = _VSTD::__to_address(__get_pointer());
2209 traits_type::move(__p, __s, __n);
2210 traits_type::assign(__p[__n], value_type());
2211 __set_size(__n);
2212 __invalidate_iterators_past(__n);
2213 }
2214 else
2215 {
2216 size_type __sz = size();
2217 __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s);
2218 }
2219 return *this;
2306 return (_LIBCPP_BUILTIN_CONSTANT_P(__n) && __n < __min_cap)
2307 ? __assign_short(__s, __n)
2308 : __assign_external(__s, __n);
22202309}
22212310
22222311template <class _CharT, class _Traits, class _Allocator>
......@@ -2263,12 +2352,19 @@ template <class _CharT, class _Traits, class _Allocator>
22632352basic_string<_CharT, _Traits, _Allocator>&
22642353basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str)
22652354{
2266 if (this != &__str)
2267 {
2268 __copy_assign_alloc(__str);
2269 return assign(__str.data(), __str.size());
2355 if (this != &__str) {
2356 __copy_assign_alloc(__str);
2357 if (!__is_long()) {
2358 if (!__str.__is_long()) {
2359 __r_.first().__r = __str.__r_.first().__r;
2360 } else {
2361 return __assign_no_alias<true>(__str.data(), __str.size());
2362 }
2363 } else {
2364 return __assign_no_alias<false>(__str.data(), __str.size());
22702365 }
2271 return *this;
2366 }
2367 return *this;
22722368}
22732369
22742370#ifndef _LIBCPP_CXX03_LANG
......@@ -2326,12 +2422,12 @@ basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str)
23262422
23272423template <class _CharT, class _Traits, class _Allocator>
23282424template<class _InputIterator>
2329typename enable_if
2425_EnableIf
23302426<
23312427 __is_exactly_cpp17_input_iterator <_InputIterator>::value
23322428 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
23332429 basic_string<_CharT, _Traits, _Allocator>&
2334>::type
2430>
23352431basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
23362432{
23372433 const basic_string __temp(__first, __last, __alloc());
......@@ -2341,12 +2437,12 @@ basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _Input
23412437
23422438template <class _CharT, class _Traits, class _Allocator>
23432439template<class _ForwardIterator>
2344typename enable_if
2440_EnableIf
23452441<
23462442 __is_cpp17_forward_iterator<_ForwardIterator>::value
23472443 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
23482444 basic_string<_CharT, _Traits, _Allocator>&
2349>::type
2445>
23502446basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
23512447{
23522448 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
......@@ -2378,11 +2474,12 @@ basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, siz
23782474
23792475template <class _CharT, class _Traits, class _Allocator>
23802476template <class _Tp>
2381typename enable_if
2477_EnableIf
23822478<
2383 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
2479 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
2480 && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
23842481 basic_string<_CharT, _Traits, _Allocator>&
2385>::type
2482>
23862483basic_string<_CharT, _Traits, _Allocator>::assign(const _Tp & __t, size_type __pos, size_type __n)
23872484{
23882485 __self_view __sv = __t;
......@@ -2393,14 +2490,23 @@ basic_string<_CharT, _Traits, _Allocator>::assign(const _Tp & __t, size_type __p
23932490}
23942491
23952492
2493template <class _CharT, class _Traits, class _Allocator>
2494basic_string<_CharT, _Traits, _Allocator>&
2495basic_string<_CharT, _Traits, _Allocator>::__assign_external(const value_type* __s) {
2496 return __assign_external(__s, traits_type::length(__s));
2497}
2498
23962499template <class _CharT, class _Traits, class _Allocator>
23972500basic_string<_CharT, _Traits, _Allocator>&
23982501basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s)
23992502{
24002503 _LIBCPP_ASSERT(__s != nullptr, "string::assign received nullptr");
2401 return assign(__s, traits_type::length(__s));
2504 return _LIBCPP_BUILTIN_CONSTANT_P(*__s)
2505 ? (traits_type::length(__s) < __min_cap
2506 ? __assign_short(__s, traits_type::length(__s))
2507 : __assign_external(__s, traits_type::length(__s)))
2508 : __assign_external(__s);
24022509}
2403
24042510// append
24052511
24062512template <class _CharT, class _Traits, class _Allocator>
......@@ -2565,11 +2671,11 @@ basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, siz
25652671
25662672template <class _CharT, class _Traits, class _Allocator>
25672673template <class _Tp>
2568 typename enable_if
2674 _EnableIf
25692675 <
2570 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
2676 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
25712677 basic_string<_CharT, _Traits, _Allocator>&
2572 >::type
2678 >
25732679basic_string<_CharT, _Traits, _Allocator>::append(const _Tp & __t, size_type __pos, size_type __n)
25742680{
25752681 __self_view __sv = __t;
......@@ -2654,12 +2760,12 @@ basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n
26542760
26552761template <class _CharT, class _Traits, class _Allocator>
26562762template<class _InputIterator>
2657typename enable_if
2763_EnableIf
26582764<
26592765 __is_exactly_cpp17_input_iterator<_InputIterator>::value
26602766 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
26612767 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2662>::type
2768>
26632769basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last)
26642770{
26652771#if _LIBCPP_DEBUG_LEVEL >= 2
......@@ -2673,12 +2779,12 @@ basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIt
26732779
26742780template <class _CharT, class _Traits, class _Allocator>
26752781template<class _ForwardIterator>
2676typename enable_if
2782_EnableIf
26772783<
26782784 __is_cpp17_forward_iterator<_ForwardIterator>::value
26792785 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
26802786 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2681>::type
2787>
26822788basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last)
26832789{
26842790#if _LIBCPP_DEBUG_LEVEL >= 2
......@@ -2743,11 +2849,11 @@ basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_
27432849
27442850template <class _CharT, class _Traits, class _Allocator>
27452851template <class _Tp>
2746typename enable_if
2852_EnableIf
27472853<
2748 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
2854 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
27492855 basic_string<_CharT, _Traits, _Allocator>&
2750>::type
2856>
27512857basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const _Tp& __t,
27522858 size_type __pos2, size_type __n)
27532859{
......@@ -2852,8 +2958,8 @@ basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __
28522958 }
28532959 traits_type::move(__p + __pos, __s, __n2);
28542960__finish:
2855// __sz += __n2 - __n1; in this and the below function below can cause unsigned integer overflow,
2856// but this is a safe operation, so we disable the check.
2961// __sz += __n2 - __n1; in this and the below function below can cause unsigned
2962// integer overflow, but this is a safe operation, so we disable the check.
28572963 __sz += __n2 - __n1;
28582964 __set_size(__sz);
28592965 __invalidate_iterators_past(__sz);
......@@ -2900,11 +3006,11 @@ basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __
29003006
29013007template <class _CharT, class _Traits, class _Allocator>
29023008template<class _InputIterator>
2903typename enable_if
3009_EnableIf
29043010<
29053011 __is_cpp17_input_iterator<_InputIterator>::value,
29063012 basic_string<_CharT, _Traits, _Allocator>&
2907>::type
3013>
29083014basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2,
29093015 _InputIterator __j1, _InputIterator __j2)
29103016{
......@@ -2933,11 +3039,11 @@ basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type _
29333039
29343040template <class _CharT, class _Traits, class _Allocator>
29353041template <class _Tp>
2936typename enable_if
3042_EnableIf
29373043<
2938 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3044 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
29393045 basic_string<_CharT, _Traits, _Allocator>&
2940>::type
3046>
29413047basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const _Tp& __t,
29423048 size_type __pos2, size_type __n2)
29433049{
......@@ -2991,15 +3097,16 @@ basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_it
29913097
29923098// erase
29933099
3100// 'externally instantiated' erase() implementation, called when __n != npos.
3101// Does not check __pos against size()
29943102template <class _CharT, class _Traits, class _Allocator>
2995basic_string<_CharT, _Traits, _Allocator>&
2996basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos, size_type __n)
3103void
3104basic_string<_CharT, _Traits, _Allocator>::__erase_external_with_move(
3105 size_type __pos, size_type __n)
29973106{
2998 size_type __sz = size();
2999 if (__pos > __sz)
3000 this->__throw_out_of_range();
30013107 if (__n)
30023108 {
3109 size_type __sz = size();
30033110 value_type* __p = _VSTD::__to_address(__get_pointer());
30043111 __n = _VSTD::min(__n, __sz - __pos);
30053112 size_type __n_move = __sz - __pos - __n;
......@@ -3010,7 +3117,19 @@ basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos, size_type __n)
30103117 __invalidate_iterators_past(__sz);
30113118 traits_type::assign(__p[__sz], value_type());
30123119 }
3013 return *this;
3120}
3121
3122template <class _CharT, class _Traits, class _Allocator>
3123basic_string<_CharT, _Traits, _Allocator>&
3124basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos,
3125 size_type __n) {
3126 if (__pos > size()) this->__throw_out_of_range();
3127 if (__n == npos) {
3128 __erase_to_end(__pos);
3129 } else {
3130 __erase_external_with_move(__pos, __n);
3131 }
3132 return *this;
30143133}
30153134
30163135template <class _CharT, class _Traits, class _Allocator>
......@@ -3356,11 +3475,11 @@ basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str,
33563475
33573476template<class _CharT, class _Traits, class _Allocator>
33583477template <class _Tp>
3359typename enable_if
3478_EnableIf
33603479<
33613480 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
33623481 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3363>::type
3482>
33643483basic_string<_CharT, _Traits, _Allocator>::find(const _Tp &__t,
33653484 size_type __pos) const
33663485{
......@@ -3414,11 +3533,11 @@ basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str,
34143533
34153534template<class _CharT, class _Traits, class _Allocator>
34163535template <class _Tp>
3417typename enable_if
3536_EnableIf
34183537<
34193538 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
34203539 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3421>::type
3540>
34223541basic_string<_CharT, _Traits, _Allocator>::rfind(const _Tp& __t,
34233542 size_type __pos) const
34243543{
......@@ -3472,11 +3591,11 @@ basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __s
34723591
34733592template<class _CharT, class _Traits, class _Allocator>
34743593template <class _Tp>
3475typename enable_if
3594_EnableIf
34763595<
34773596 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
34783597 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3479>::type
3598>
34803599basic_string<_CharT, _Traits, _Allocator>::find_first_of(const _Tp& __t,
34813600 size_type __pos) const
34823601{
......@@ -3530,11 +3649,11 @@ basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __st
35303649
35313650template<class _CharT, class _Traits, class _Allocator>
35323651template <class _Tp>
3533typename enable_if
3652_EnableIf
35343653<
35353654 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
35363655 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3537>::type
3656>
35383657basic_string<_CharT, _Traits, _Allocator>::find_last_of(const _Tp& __t,
35393658 size_type __pos) const
35403659{
......@@ -3588,11 +3707,11 @@ basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string&
35883707
35893708template<class _CharT, class _Traits, class _Allocator>
35903709template <class _Tp>
3591typename enable_if
3710_EnableIf
35923711<
35933712 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
35943713 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3595>::type
3714>
35963715basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const _Tp& __t,
35973716 size_type __pos) const
35983717{
......@@ -3647,11 +3766,11 @@ basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string&
36473766
36483767template<class _CharT, class _Traits, class _Allocator>
36493768template <class _Tp>
3650typename enable_if
3769_EnableIf
36513770<
36523771 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
36533772 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3654>::type
3773>
36553774basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const _Tp& __t,
36563775 size_type __pos) const
36573776{
......@@ -3685,11 +3804,11 @@ basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c,
36853804
36863805template <class _CharT, class _Traits, class _Allocator>
36873806template <class _Tp>
3688typename enable_if
3807_EnableIf
36893808<
36903809 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
36913810 int
3692>::type
3811>
36933812basic_string<_CharT, _Traits, _Allocator>::compare(const _Tp& __t) const
36943813{
36953814 __self_view __sv = __t;
......@@ -3739,11 +3858,11 @@ basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
37393858
37403859template <class _CharT, class _Traits, class _Allocator>
37413860template <class _Tp>
3742typename enable_if
3861_EnableIf
37433862<
37443863 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
37453864 int
3746>::type
3865>
37473866basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
37483867 size_type __n1,
37493868 const _Tp& __t) const
......@@ -3764,11 +3883,12 @@ basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
37643883
37653884template <class _CharT, class _Traits, class _Allocator>
37663885template <class _Tp>
3767typename enable_if
3886_EnableIf
37683887<
3769 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3888 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
3889 && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
37703890 int
3771>::type
3891>
37723892basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
37733893 size_type __n1,
37743894 const _Tp& __t,
......@@ -4230,8 +4350,9 @@ _LIBCPP_FUNC_VIS wstring to_wstring(double __val);
42304350_LIBCPP_FUNC_VIS wstring to_wstring(long double __val);
42314351
42324352template<class _CharT, class _Traits, class _Allocator>
4233 const typename basic_string<_CharT, _Traits, _Allocator>::size_type
4234 basic_string<_CharT, _Traits, _Allocator>::npos;
4353_LIBCPP_FUNC_VIS
4354const typename basic_string<_CharT, _Traits, _Allocator>::size_type
4355 basic_string<_CharT, _Traits, _Allocator>::npos;
42354356
42364357template <class _CharT, class _Allocator>
42374358struct _LIBCPP_TEMPLATE_VIS
......@@ -4283,15 +4404,25 @@ getline(basic_istream<_CharT, _Traits>&& __is,
42834404#endif // _LIBCPP_CXX03_LANG
42844405
42854406#if _LIBCPP_STD_VER > 17
4286template<class _CharT, class _Traits, class _Allocator, class _Up>
4407template <class _CharT, class _Traits, class _Allocator, class _Up>
42874408inline _LIBCPP_INLINE_VISIBILITY
4288void erase(basic_string<_CharT, _Traits, _Allocator>& __str, const _Up& __v)
4289{ __str.erase(_VSTD::remove(__str.begin(), __str.end(), __v), __str.end()); }
4409 typename basic_string<_CharT, _Traits, _Allocator>::size_type
4410 erase(basic_string<_CharT, _Traits, _Allocator>& __str, const _Up& __v) {
4411 auto __old_size = __str.size();
4412 __str.erase(_VSTD::remove(__str.begin(), __str.end(), __v), __str.end());
4413 return __old_size - __str.size();
4414}
42904415
4291template<class _CharT, class _Traits, class _Allocator, class _Predicate>
4416template <class _CharT, class _Traits, class _Allocator, class _Predicate>
42924417inline _LIBCPP_INLINE_VISIBILITY
4293void erase_if(basic_string<_CharT, _Traits, _Allocator>& __str, _Predicate __pred)
4294{ __str.erase(_VSTD::remove_if(__str.begin(), __str.end(), __pred), __str.end()); }
4418 typename basic_string<_CharT, _Traits, _Allocator>::size_type
4419 erase_if(basic_string<_CharT, _Traits, _Allocator>& __str,
4420 _Predicate __pred) {
4421 auto __old_size = __str.size();
4422 __str.erase(_VSTD::remove_if(__str.begin(), __str.end(), __pred),
4423 __str.end());
4424 return __old_size - __str.size();
4425}
42954426#endif
42964427
42974428#if _LIBCPP_DEBUG_LEVEL >= 2
......@@ -4330,9 +4461,6 @@ basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator*
43304461
43314462#endif // _LIBCPP_DEBUG_LEVEL >= 2
43324463
4333_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string<char>)
4334_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string<wchar_t>)
4335
43364464#if _LIBCPP_STD_VER > 11
43374465// Literal suffixes for basic_string [basic.string.literals]
43384466inline namespace literals
lib/libcxx/include/system_error+1
......@@ -469,6 +469,7 @@ public:
469469 system_error(int __ev, const error_category& __ecat, const string& __what_arg);
470470 system_error(int __ev, const error_category& __ecat, const char* __what_arg);
471471 system_error(int __ev, const error_category& __ecat);
472 system_error(const system_error&) _NOEXCEPT = default;
472473 ~system_error() _NOEXCEPT;
473474
474475 _LIBCPP_INLINE_VISIBILITY
lib/libcxx/include/thread+13-17
......@@ -241,12 +241,19 @@ public:
241241#endif
242242 ~thread();
243243
244#ifndef _LIBCPP_CXX03_LANG
245244 _LIBCPP_INLINE_VISIBILITY
246 thread(thread&& __t) _NOEXCEPT : __t_(__t.__t_) {__t.__t_ = _LIBCPP_NULL_THREAD;}
245 thread(thread&& __t) _NOEXCEPT : __t_(__t.__t_) {
246 __t.__t_ = _LIBCPP_NULL_THREAD;
247 }
248
247249 _LIBCPP_INLINE_VISIBILITY
248 thread& operator=(thread&& __t) _NOEXCEPT;
249#endif // _LIBCPP_CXX03_LANG
250 thread& operator=(thread&& __t) _NOEXCEPT {
251 if (!__libcpp_thread_isnull(&__t_))
252 terminate();
253 __t_ = __t.__t_;
254 __t.__t_ = _LIBCPP_NULL_THREAD;
255 return *this;
256 }
250257
251258 _LIBCPP_INLINE_VISIBILITY
252259 void swap(thread& __t) _NOEXCEPT {_VSTD::swap(__t_, __t.__t_);}
......@@ -304,17 +311,6 @@ thread::thread(_Fp&& __f, _Args&&... __args)
304311 __throw_system_error(__ec, "thread constructor failed");
305312}
306313
307inline
308thread&
309thread::operator=(thread&& __t) _NOEXCEPT
310{
311 if (!__libcpp_thread_isnull(&__t_))
312 terminate();
313 __t_ = __t.__t_;
314 __t.__t_ = _LIBCPP_NULL_THREAD;
315 return *this;
316}
317
318314#else // _LIBCPP_CXX03_LANG
319315
320316template <class _Fp>
......@@ -369,9 +365,9 @@ sleep_for(const chrono::duration<_Rep, _Period>& __d)
369365 {
370366#if defined(_LIBCPP_COMPILER_GCC) && (__powerpc__ || __POWERPC__)
371367 // GCC's long double const folding is incomplete for IBM128 long doubles.
372 _LIBCPP_CONSTEXPR duration<long double> _Max = nanoseconds::max();
373#else
374368 _LIBCPP_CONSTEXPR duration<long double> _Max = duration<long double>(ULLONG_MAX/1000000000ULL) ;
369#else
370 _LIBCPP_CONSTEXPR duration<long double> _Max = nanoseconds::max();
375371#endif
376372 nanoseconds __ns;
377373 if (__d < _Max)
lib/libcxx/include/type_traits+391-56
......@@ -544,6 +544,18 @@ template <bool _Bp, class _Tp = void> using enable_if_t = typename enable_if<_Bp
544544
545545// is_same
546546
547#if __has_keyword(__is_same)
548
549template <class _Tp, class _Up>
550struct _LIBCPP_TEMPLATE_VIS is_same : _BoolConstant<__is_same(_Tp, _Up)> { };
551
552#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
553template <class _Tp, class _Up>
554_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_same_v = __is_same(_Tp, _Up);
555#endif
556
557#else
558
547559template <class _Tp, class _Up> struct _LIBCPP_TEMPLATE_VIS is_same : public false_type {};
548560template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_same<_Tp, _Tp> : public true_type {};
549561
......@@ -553,6 +565,8 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_same_v
553565 = is_same<_Tp, _Up>::value;
554566#endif
555567
568#endif // __is_same
569
556570template <class _Tp, class _Up>
557571using _IsSame = _BoolConstant<
558572#ifdef __clang__
......@@ -656,6 +670,18 @@ struct __two {char __lx[2];};
656670
657671// is_const
658672
673#if __has_keyword(__is_const)
674
675template <class _Tp>
676struct _LIBCPP_TEMPLATE_VIS is_const : _BoolConstant<__is_const(_Tp)> { };
677
678#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
679template <class _Tp>
680_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_const_v = __is_const(_Tp);
681#endif
682
683#else
684
659685template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_const : public false_type {};
660686template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_const<_Tp const> : public true_type {};
661687
......@@ -665,8 +691,22 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_const_v
665691 = is_const<_Tp>::value;
666692#endif
667693
694#endif // __has_keyword(__is_const)
695
668696// is_volatile
669697
698#if __has_keyword(__is_volatile)
699
700template <class _Tp>
701struct _LIBCPP_TEMPLATE_VIS is_volatile : _BoolConstant<__is_volatile(_Tp)> { };
702
703#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
704template <class _Tp>
705_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_volatile_v = __is_volatile(_Tp);
706#endif
707
708#else
709
670710template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_volatile : public false_type {};
671711template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_volatile<_Tp volatile> : public true_type {};
672712
......@@ -676,37 +716,87 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_volatile_v
676716 = is_volatile<_Tp>::value;
677717#endif
678718
719#endif // __has_keyword(__is_volatile)
720
679721// remove_const
680722
723#if __has_keyword(__remove_const)
724
725template <class _Tp>
726struct _LIBCPP_TEMPLATE_VIS remove_const {typedef __remove_const(_Tp) type;};
727
728#if _LIBCPP_STD_VER > 11
729template <class _Tp> using remove_const_t = __remove_const(_Tp);
730#endif
731
732#else
733
681734template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_const {typedef _Tp type;};
682735template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_const<const _Tp> {typedef _Tp type;};
683736#if _LIBCPP_STD_VER > 11
684737template <class _Tp> using remove_const_t = typename remove_const<_Tp>::type;
685738#endif
686739
740#endif // __has_keyword(__remove_const)
741
687742// remove_volatile
688743
744#if __has_keyword(__remove_volatile)
745
746template <class _Tp>
747struct _LIBCPP_TEMPLATE_VIS remove_volatile {typedef __remove_volatile(_Tp) type;};
748
749#if _LIBCPP_STD_VER > 11
750template <class _Tp> using remove_volatile_t = __remove_volatile(_Tp);
751#endif
752
753#else
754
689755template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_volatile {typedef _Tp type;};
690756template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_volatile<volatile _Tp> {typedef _Tp type;};
691757#if _LIBCPP_STD_VER > 11
692758template <class _Tp> using remove_volatile_t = typename remove_volatile<_Tp>::type;
693759#endif
694760
761#endif // __has_keyword(__remove_volatile)
762
695763// remove_cv
696764
765#if __has_keyword(__remove_cv)
766
767template <class _Tp>
768struct _LIBCPP_TEMPLATE_VIS remove_cv {typedef __remove_cv(_Tp) type;};
769
770#if _LIBCPP_STD_VER > 11
771template <class _Tp> using remove_cv_t = __remove_cv(_Tp);
772#endif
773
774#else
775
697776template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_cv
698777{typedef typename remove_volatile<typename remove_const<_Tp>::type>::type type;};
699778#if _LIBCPP_STD_VER > 11
700779template <class _Tp> using remove_cv_t = typename remove_cv<_Tp>::type;
701780#endif
702781
782#endif // __has_keyword(__remove_cv)
783
703784// is_void
704785
705template <class _Tp> struct __libcpp_is_void : public false_type {};
706template <> struct __libcpp_is_void<void> : public true_type {};
786#if __has_keyword(__is_void)
787
788template <class _Tp>
789struct _LIBCPP_TEMPLATE_VIS is_void : _BoolConstant<__is_void(_Tp)> { };
790
791#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
792template <class _Tp>
793_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_void_v = __is_void(_Tp);
794#endif
795
796#else
707797
708798template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_void
709 : public __libcpp_is_void<typename remove_cv<_Tp>::type> {};
799 : public is_same<typename remove_cv<_Tp>::type, void> {};
710800
711801#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
712802template <class _Tp>
......@@ -714,6 +804,8 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_void_v
714804 = is_void<_Tp>::value;
715805#endif
716806
807#endif // __has_keyword(__is_void)
808
717809// __is_nullptr_t
718810
719811template <class _Tp> struct __is_nullptr_t_impl : public false_type {};
......@@ -735,34 +827,20 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_null_pointer_v
735827
736828// is_integral
737829
738template <class _Tp> struct __libcpp_is_integral : public false_type {};
739template <> struct __libcpp_is_integral<bool> : public true_type {};
740template <> struct __libcpp_is_integral<char> : public true_type {};
741template <> struct __libcpp_is_integral<signed char> : public true_type {};
742template <> struct __libcpp_is_integral<unsigned char> : public true_type {};
743template <> struct __libcpp_is_integral<wchar_t> : public true_type {};
744#ifndef _LIBCPP_NO_HAS_CHAR8_T
745template <> struct __libcpp_is_integral<char8_t> : public true_type {};
746#endif
747#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
748template <> struct __libcpp_is_integral<char16_t> : public true_type {};
749template <> struct __libcpp_is_integral<char32_t> : public true_type {};
750#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
751template <> struct __libcpp_is_integral<short> : public true_type {};
752template <> struct __libcpp_is_integral<unsigned short> : public true_type {};
753template <> struct __libcpp_is_integral<int> : public true_type {};
754template <> struct __libcpp_is_integral<unsigned int> : public true_type {};
755template <> struct __libcpp_is_integral<long> : public true_type {};
756template <> struct __libcpp_is_integral<unsigned long> : public true_type {};
757template <> struct __libcpp_is_integral<long long> : public true_type {};
758template <> struct __libcpp_is_integral<unsigned long long> : public true_type {};
759#ifndef _LIBCPP_HAS_NO_INT128
760template <> struct __libcpp_is_integral<__int128_t> : public true_type {};
761template <> struct __libcpp_is_integral<__uint128_t> : public true_type {};
830#if __has_keyword(__is_integral)
831
832template <class _Tp>
833struct _LIBCPP_TEMPLATE_VIS is_integral : _BoolConstant<__is_integral(_Tp)> { };
834
835#if _LIBCPP_STD_VER > 14
836template <class _Tp>
837_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_integral_v = __is_integral(_Tp);
762838#endif
763839
840#else
841
764842template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_integral
765 : public __libcpp_is_integral<typename remove_cv<_Tp>::type> {};
843 : public _BoolConstant<__libcpp_is_integral<typename remove_cv<_Tp>::type>::value> {};
766844
767845#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
768846template <class _Tp>
......@@ -770,6 +848,8 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_integral_v
770848 = is_integral<_Tp>::value;
771849#endif
772850
851#endif // __has_keyword(__is_integral)
852
773853// is_floating_point
774854
775855template <class _Tp> struct __libcpp_is_floating_point : public false_type {};
......@@ -788,6 +868,18 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_floating_point_v
788868
789869// is_array
790870
871#if __has_keyword(__is_array)
872
873template <class _Tp>
874struct _LIBCPP_TEMPLATE_VIS is_array : _BoolConstant<__is_array(_Tp)> { };
875
876#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
877template <class _Tp>
878_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_array_v = __is_array(_Tp);
879#endif
880
881#else
882
791883template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_array
792884 : public false_type {};
793885template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_array<_Tp[]>
......@@ -801,8 +893,23 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_array_v
801893 = is_array<_Tp>::value;
802894#endif
803895
896#endif // __has_keyword(__is_array)
897
804898// is_pointer
805899
900// In clang 10.0.0 and earlier __is_pointer didn't work with Objective-C types.
901#if __has_keyword(__is_pointer) && _LIBCPP_CLANG_VER > 1000
902
903template<class _Tp>
904struct _LIBCPP_TEMPLATE_VIS is_pointer : _BoolConstant<__is_pointer(_Tp)> { };
905
906#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
907template <class _Tp>
908_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_pointer_v = __is_pointer(_Tp);
909#endif
910
911#else // __has_keyword(__is_pointer)
912
806913template <class _Tp> struct __libcpp_is_pointer : public false_type {};
807914template <class _Tp> struct __libcpp_is_pointer<_Tp*> : public true_type {};
808915
......@@ -823,8 +930,36 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_pointer_v
823930 = is_pointer<_Tp>::value;
824931#endif
825932
933#endif // __has_keyword(__is_pointer)
934
826935// is_reference
827936
937#if __has_keyword(__is_lvalue_reference) && \
938 __has_keyword(__is_rvalue_reference) && \
939 __has_keyword(__is_reference)
940
941template<class _Tp>
942struct _LIBCPP_TEMPLATE_VIS is_lvalue_reference : _BoolConstant<__is_lvalue_reference(_Tp)> { };
943
944template<class _Tp>
945struct _LIBCPP_TEMPLATE_VIS is_rvalue_reference : _BoolConstant<__is_rvalue_reference(_Tp)> { };
946
947template<class _Tp>
948struct _LIBCPP_TEMPLATE_VIS is_reference : _BoolConstant<__is_reference(_Tp)> { };
949
950#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
951template <class _Tp>
952_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_reference_v = __is_reference(_Tp);
953
954template <class _Tp>
955_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_lvalue_reference_v = __is_lvalue_reference(_Tp);
956
957template <class _Tp>
958_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_rvalue_reference_v = __is_rvalue_reference(_Tp);
959#endif
960
961#else // __has_keyword(__is_lvalue_reference) && etc...
962
828963template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_lvalue_reference : public false_type {};
829964template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_lvalue_reference<_Tp&> : public true_type {};
830965
......@@ -848,6 +983,9 @@ template <class _Tp>
848983_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_rvalue_reference_v
849984 = is_rvalue_reference<_Tp>::value;
850985#endif
986
987#endif // __has_keyword(__is_lvalue_reference) && etc...
988
851989// is_union
852990
853991#if __has_feature(is_union) || defined(_LIBCPP_COMPILER_GCC)
......@@ -928,6 +1066,19 @@ template <class _Tp, class _Up> struct __libcpp_is_member_pointer<_Tp _Up::*> {
9281066 };
9291067};
9301068
1069#if __has_keyword(__is_member_function_pointer)
1070
1071template<class _Tp>
1072struct _LIBCPP_TEMPLATE_VIS is_member_function_pointer
1073 : _BoolConstant<__is_member_function_pointer(_Tp)> { };
1074
1075#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1076template <class _Tp>
1077_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_member_function_pointer_v
1078 = __is_member_function_pointer(_Tp);
1079#endif
1080
1081#else // __has_keyword(__is_member_function_pointer)
9311082
9321083template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_member_function_pointer
9331084 : public _BoolConstant< __libcpp_is_member_pointer<typename remove_cv<_Tp>::type>::__is_func > {};
......@@ -938,8 +1089,22 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_member_function_pointer_v
9381089 = is_member_function_pointer<_Tp>::value;
9391090#endif
9401091
1092#endif // __has_keyword(__is_member_function_pointer)
1093
9411094// is_member_pointer
9421095
1096#if __has_keyword(__is_member_pointer)
1097
1098template<class _Tp>
1099struct _LIBCPP_TEMPLATE_VIS is_member_pointer : _BoolConstant<__is_member_pointer(_Tp)> { };
1100
1101#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1102template <class _Tp>
1103_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_member_pointer_v = __is_member_pointer(_Tp);
1104#endif
1105
1106#else // __has_keyword(__is_member_pointer)
1107
9431108template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_member_pointer
9441109 : public _BoolConstant< __libcpp_is_member_pointer<typename remove_cv<_Tp>::type>::__is_member > {};
9451110
......@@ -949,8 +1114,24 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_member_pointer_v
9491114 = is_member_pointer<_Tp>::value;
9501115#endif
9511116
1117#endif // __has_keyword(__is_member_pointer)
1118
9521119// is_member_object_pointer
9531120
1121#if __has_keyword(__is_member_object_pointer)
1122
1123template<class _Tp>
1124struct _LIBCPP_TEMPLATE_VIS is_member_object_pointer
1125 : _BoolConstant<__is_member_object_pointer(_Tp)> { };
1126
1127#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1128template <class _Tp>
1129_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_member_object_pointer_v
1130 = __is_member_object_pointer(_Tp);
1131#endif
1132
1133#else // __has_keyword(__is_member_object_pointer)
1134
9541135template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_member_object_pointer
9551136 : public _BoolConstant< __libcpp_is_member_pointer<typename remove_cv<_Tp>::type>::__is_obj > {};
9561137
......@@ -960,6 +1141,8 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_member_object_pointer_v
9601141 = is_member_object_pointer<_Tp>::value;
9611142#endif
9621143
1144#endif // __has_keyword(__is_member_object_pointer)
1145
9631146// is_enum
9641147
9651148#if __has_feature(is_enum) || defined(_LIBCPP_COMPILER_GCC)
......@@ -967,6 +1150,11 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_member_object_pointer_v
9671150template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_enum
9681151 : public integral_constant<bool, __is_enum(_Tp)> {};
9691152
1153#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1154template <class _Tp>
1155_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_enum_v = __is_enum(_Tp);
1156#endif
1157
9701158#else
9711159
9721160template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_enum
......@@ -981,16 +1169,17 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_enum
9811169 !is_class<_Tp>::value &&
9821170 !is_function<_Tp>::value > {};
9831171
984#endif
985
9861172#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
9871173template <class _Tp>
9881174_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_enum_v
9891175 = is_enum<_Tp>::value;
9901176#endif
9911177
1178#endif // __has_feature(is_enum) || defined(_LIBCPP_COMPILER_GCC)
1179
9921180// is_arithmetic
9931181
1182
9941183template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_arithmetic
9951184 : public integral_constant<bool, is_integral<_Tp>::value ||
9961185 is_floating_point<_Tp>::value> {};
......@@ -1003,6 +1192,20 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_arithmetic_v
10031192
10041193// is_fundamental
10051194
1195// In clang 9 and lower, this builtin did not work for nullptr_t. Additionally, in C++03 mode,
1196// nullptr isn't defined by the compiler so, this builtin won't work.
1197#if __has_keyword(__is_fundamental) && _LIBCPP_CLANG_VER > 900 && !defined(_LIBCPP_CXX03_LANG)
1198
1199template<class _Tp>
1200struct _LIBCPP_TEMPLATE_VIS is_fundamental : _BoolConstant<__is_fundamental(_Tp)> { };
1201
1202#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1203template <class _Tp>
1204_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_fundamental_v = __is_fundamental(_Tp);
1205#endif
1206
1207#else // __has_keyword(__is_fundamental)
1208
10061209template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_fundamental
10071210 : public integral_constant<bool, is_void<_Tp>::value ||
10081211 __is_nullptr_t<_Tp>::value ||
......@@ -1014,13 +1217,34 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_fundamental_v
10141217 = is_fundamental<_Tp>::value;
10151218#endif
10161219
1220#endif // __has_keyword(__is_fundamental)
1221
10171222// is_scalar
10181223
1224// >= 11 because in C++03 nullptr isn't actually nullptr
1225#if __has_keyword(__is_scalar) && !defined(_LIBCPP_CXX03_LANG)
1226
1227template<class _Tp>
1228struct _LIBCPP_TEMPLATE_VIS is_scalar : _BoolConstant<__is_scalar(_Tp)> { };
1229
1230#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1231template <class _Tp>
1232_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_scalar_v = __is_scalar(_Tp);
1233#endif
1234
1235#else // __has_keyword(__is_scalar)
1236
1237template <class _Tp> struct __is_block : false_type {};
1238#if defined(_LIBCPP_HAS_EXTENSION_BLOCKS)
1239template <class _Rp, class ..._Args> struct __is_block<_Rp (^)(_Args...)> : true_type {};
1240#endif
1241
10191242template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_scalar
10201243 : public integral_constant<bool, is_arithmetic<_Tp>::value ||
10211244 is_member_pointer<_Tp>::value ||
10221245 is_pointer<_Tp>::value ||
10231246 __is_nullptr_t<_Tp>::value ||
1247 __is_block<_Tp>::value ||
10241248 is_enum<_Tp>::value > {};
10251249
10261250template <> struct _LIBCPP_TEMPLATE_VIS is_scalar<nullptr_t> : public true_type {};
......@@ -1031,8 +1255,22 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_scalar_v
10311255 = is_scalar<_Tp>::value;
10321256#endif
10331257
1258#endif // __has_keyword(__is_scalar)
1259
10341260// is_object
10351261
1262#if __has_keyword(__is_object)
1263
1264template<class _Tp>
1265struct _LIBCPP_TEMPLATE_VIS is_object : _BoolConstant<__is_object(_Tp)> { };
1266
1267#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1268template <class _Tp>
1269_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_object_v = __is_object(_Tp);
1270#endif
1271
1272#else // __has_keyword(__is_object)
1273
10361274template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_object
10371275 : public integral_constant<bool, is_scalar<_Tp>::value ||
10381276 is_array<_Tp>::value ||
......@@ -1045,8 +1283,23 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_object_v
10451283 = is_object<_Tp>::value;
10461284#endif
10471285
1286#endif // __has_keyword(__is_object)
1287
10481288// is_compound
10491289
1290// >= 11 because in C++03 nullptr isn't actually nullptr
1291#if __has_keyword(__is_compound) && !defined(_LIBCPP_CXX03_LANG)
1292
1293template<class _Tp>
1294struct _LIBCPP_TEMPLATE_VIS is_compound : _BoolConstant<__is_compound(_Tp)> { };
1295
1296#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1297template <class _Tp>
1298_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_compound_v = __is_compound(_Tp);
1299#endif
1300
1301#else // __has_keyword(__is_compound)
1302
10501303template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_compound
10511304 : public integral_constant<bool, !is_fundamental<_Tp>::value> {};
10521305
......@@ -1056,6 +1309,7 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_compound_v
10561309 = is_compound<_Tp>::value;
10571310#endif
10581311
1312#endif // __has_keyword(__is_compound)
10591313
10601314// __is_referenceable [defns.referenceable]
10611315
......@@ -1100,6 +1354,13 @@ template <class _Tp> using add_cv_t = typename add_cv<_Tp>::type;
11001354
11011355// remove_reference
11021356
1357#if __has_keyword(__remove_reference)
1358
1359template<class _Tp>
1360struct _LIBCPP_TEMPLATE_VIS remove_reference { typedef __remove_reference(_Tp) type; };
1361
1362#else // __has_keyword(__remove_reference)
1363
11031364template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_reference {typedef _LIBCPP_NODEBUG_TYPE _Tp type;};
11041365template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_reference<_Tp&> {typedef _LIBCPP_NODEBUG_TYPE _Tp type;};
11051366template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_reference<_Tp&&> {typedef _LIBCPP_NODEBUG_TYPE _Tp type;};
......@@ -1108,6 +1369,8 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_reference<_Tp&&> {typede
11081369template <class _Tp> using remove_reference_t = typename remove_reference<_Tp>::type;
11091370#endif
11101371
1372#endif // __has_keyword(__remove_reference)
1373
11111374// add_lvalue_reference
11121375
11131376template <class _Tp, bool = __is_referenceable<_Tp>::value> struct __add_lvalue_reference_impl { typedef _LIBCPP_NODEBUG_TYPE _Tp type; };
......@@ -1215,6 +1478,19 @@ template<class _Tp> using type_identity_t = typename type_identity<_Tp>::type;
12151478
12161479// is_signed
12171480
1481// In clang 9 and earlier, this builtin did not work for floating points or enums
1482#if __has_keyword(__is_signed) && _LIBCPP_CLANG_VER > 900
1483
1484template<class _Tp>
1485struct _LIBCPP_TEMPLATE_VIS is_signed : _BoolConstant<__is_signed(_Tp)> { };
1486
1487#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1488template <class _Tp>
1489_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_signed_v = __is_signed(_Tp);
1490#endif
1491
1492#else // __has_keyword(__is_signed)
1493
12181494template <class _Tp, bool = is_integral<_Tp>::value>
12191495struct __libcpp_is_signed_impl : public _LIBCPP_BOOL_CONSTANT(_Tp(-1) < _Tp(0)) {};
12201496
......@@ -1234,8 +1510,22 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_signed_v
12341510 = is_signed<_Tp>::value;
12351511#endif
12361512
1513#endif // __has_keyword(__is_signed)
1514
12371515// is_unsigned
12381516
1517#if __has_keyword(__is_unsigned)
1518
1519template<class _Tp>
1520struct _LIBCPP_TEMPLATE_VIS is_unsigned : _BoolConstant<__is_unsigned(_Tp)> { };
1521
1522#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1523template <class _Tp>
1524_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_unsigned_v = __is_unsigned(_Tp);
1525#endif
1526
1527#else // __has_keyword(__is_unsigned)
1528
12391529template <class _Tp, bool = is_integral<_Tp>::value>
12401530struct __libcpp_is_unsigned_impl : public _LIBCPP_BOOL_CONSTANT(_Tp(0) < _Tp(-1)) {};
12411531
......@@ -1255,6 +1545,8 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_unsigned_v
12551545 = is_unsigned<_Tp>::value;
12561546#endif
12571547
1548#endif // __has_keyword(__is_unsigned)
1549
12581550// rank
12591551
12601552template <class _Tp> struct _LIBCPP_TEMPLATE_VIS rank
......@@ -1272,6 +1564,19 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR size_t rank_v
12721564
12731565// extent
12741566
1567#if __has_keyword(__array_extent)
1568
1569template<class _Tp, size_t _Dim = 0>
1570struct _LIBCPP_TEMPLATE_VIS extent
1571 : integral_constant<size_t, __array_extent(_Tp, _Dim)> { };
1572
1573#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1574template <class _Tp, unsigned _Ip = 0>
1575_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR size_t extent_v = __array_extent(_Tp, _Ip);
1576#endif
1577
1578#else // __has_keyword(__array_extent)
1579
12751580template <class _Tp, unsigned _Ip = 0> struct _LIBCPP_TEMPLATE_VIS extent
12761581 : public integral_constant<size_t, 0> {};
12771582template <class _Tp> struct _LIBCPP_TEMPLATE_VIS extent<_Tp[], 0>
......@@ -1289,6 +1594,8 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR size_t extent_v
12891594 = extent<_Tp, _Ip>::value;
12901595#endif
12911596
1597#endif // __has_keyword(__array_extent)
1598
12921599// remove_extent
12931600
12941601template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_extent
......@@ -2041,9 +2348,33 @@ struct _LIBCPP_TEMPLATE_VIS make_unsigned
20412348template <class _Tp> using make_unsigned_t = typename make_unsigned<_Tp>::type;
20422349#endif
20432350
2351#if _LIBCPP_STD_VER > 14
2352template <class...> using void_t = void;
2353#endif
2354
2355#if _LIBCPP_STD_VER > 17
2356// Let COND_RES(X, Y) be:
2357template <class _Tp, class _Up>
2358using __cond_type = decltype(false ? _VSTD::declval<_Tp>() : _VSTD::declval<_Up>());
2359
2360template <class _Tp, class _Up, class = void>
2361struct __common_type3 {};
2362
2363// sub-bullet 4 - "if COND_RES(CREF(D1), CREF(D2)) denotes a type..."
2364template <class _Tp, class _Up>
2365struct __common_type3<_Tp, _Up, void_t<__cond_type<const _Tp&, const _Up&>>>
2366{
2367 using type = remove_cvref_t<__cond_type<const _Tp&, const _Up&>>;
2368};
2369
2370template <class _Tp, class _Up, class = void>
2371struct __common_type2_imp : __common_type3<_Tp, _Up> {};
2372#else
20442373template <class _Tp, class _Up, class = void>
20452374struct __common_type2_imp {};
2375#endif
20462376
2377// sub-bullet 3 - "if decay_t<decltype(false ? declval<D1>() : declval<D2>())> ..."
20472378template <class _Tp, class _Up>
20482379struct __common_type2_imp<_Tp, _Up,
20492380 typename __void_t<decltype(
......@@ -2107,6 +2438,7 @@ struct _LIBCPP_TEMPLATE_VIS common_type<_Tp>
21072438
21082439// bullet 3 - sizeof...(Tp) == 2
21092440
2441// sub-bullet 1 - "If is_same_v<T1, D1> is false or ..."
21102442template <class _Tp, class _Up>
21112443struct _LIBCPP_TEMPLATE_VIS common_type<_Tp, _Up>
21122444 : conditional<
......@@ -2134,6 +2466,18 @@ template <class ..._Tp> using common_type_t = typename common_type<_Tp...>::type
21342466
21352467template<typename, typename _Tp> struct __select_2nd { typedef _LIBCPP_NODEBUG_TYPE _Tp type; };
21362468
2469#if __has_keyword(__is_assignable)
2470
2471template<class _Tp, class _Up>
2472struct _LIBCPP_TEMPLATE_VIS is_assignable : _BoolConstant<__is_assignable(_Tp, _Up)> { };
2473
2474#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
2475template <class _Tp, class _Arg>
2476_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_assignable_v = __is_assignable(_Tp, _Arg);
2477#endif
2478
2479#else // __has_keyword(__is_assignable)
2480
21372481template <class _Tp, class _Arg>
21382482typename __select_2nd<decltype((_VSTD::declval<_Tp>() = _VSTD::declval<_Arg>())), true_type>::type
21392483__is_assignable_test(int);
......@@ -2162,6 +2506,8 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_assignable_v
21622506 = is_assignable<_Tp, _Arg>::value;
21632507#endif
21642508
2509#endif // __has_keyword(__is_assignable)
2510
21652511// is_copy_assignable
21662512
21672513template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_copy_assignable
......@@ -2188,6 +2534,18 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_move_assignable_v
21882534
21892535// is_destructible
21902536
2537#if __has_keyword(__is_destructible)
2538
2539template<class _Tp>
2540struct _LIBCPP_TEMPLATE_VIS is_destructible : _BoolConstant<__is_destructible(_Tp)> { };
2541
2542#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
2543template <class _Tp>
2544_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_destructible_v = __is_destructible(_Tp);
2545#endif
2546
2547#else // __has_keyword(__is_destructible)
2548
21912549// if it's a reference, return true
21922550// if it's a function, return false
21932551// if it's void, return false
......@@ -2250,6 +2608,8 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_destructible_v
22502608 = is_destructible<_Tp>::value;
22512609#endif
22522610
2611#endif // __has_keyword(__is_destructible)
2612
22532613// move
22542614
22552615template <class _Tp>
......@@ -3879,7 +4239,6 @@ struct underlying_type : __underlying_type_impl<_Tp, is_enum<_Tp>::value> {};
38794239template <class _Tp> using underlying_type_t = typename underlying_type<_Tp>::type;
38804240#endif
38814241
3882
38834242template <class _Tp, bool = is_enum<_Tp>::value>
38844243struct __sfinae_underlying_type
38854244{
......@@ -3962,8 +4321,6 @@ struct __has_operator_addressof
39624321
39634322#if _LIBCPP_STD_VER > 14
39644323
3965template <class...> using void_t = void;
3966
39674324template <class... _Args>
39684325struct conjunction : _And<_Args...> {};
39694326template<class... _Args>
......@@ -4040,29 +4397,7 @@ _LIBCPP_END_NAMESPACE_STD
40404397// std::byte
40414398namespace std // purposefully not versioned
40424399{
4043template <class _Integer>
4044 constexpr typename enable_if<is_integral_v<_Integer>, byte>::type &
4045 operator<<=(byte& __lhs, _Integer __shift) noexcept
4046 { return __lhs = __lhs << __shift; }
4047
4048template <class _Integer>
4049 constexpr typename enable_if<is_integral_v<_Integer>, byte>::type
4050 operator<< (byte __lhs, _Integer __shift) noexcept
4051 { return static_cast<byte>(static_cast<unsigned char>(static_cast<unsigned int>(__lhs) << __shift)); }
4052
4053template <class _Integer>
4054 constexpr typename enable_if<is_integral_v<_Integer>, byte>::type &
4055 operator>>=(byte& __lhs, _Integer __shift) noexcept
4056 { return __lhs = __lhs >> __shift; }
4057
4058template <class _Integer>
4059 constexpr typename enable_if<is_integral_v<_Integer>, byte>::type
4060 operator>> (byte __lhs, _Integer __shift) noexcept
4061 { return static_cast<byte>(static_cast<unsigned char>(static_cast<unsigned int>(__lhs) >> __shift)); }
4062
4063template <class _Integer>
4064 constexpr typename enable_if<is_integral_v<_Integer>, _Integer>::type
4065 to_integer(byte __b) noexcept { return static_cast<_Integer>(__b); }
4400
40664401
40674402}
40684403#endif
lib/libcxx/include/typeinfo+9-4
......@@ -60,6 +60,7 @@ public:
6060#include <exception>
6161#include <cstddef>
6262#include <cstdint>
63#include <type_traits>
6364#ifdef _LIBCPP_NO_EXCEPTIONS
6465#include <cstdlib>
6566#endif
......@@ -120,6 +121,7 @@ public:
120121// ========================================================================== //
121122// ------------------------------------------------------------------------- //
122123// Unique
124// (_LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION = 1)
123125// ------------------------------------------------------------------------- //
124126// This implementation of type_info assumes a unique copy of the RTTI for a
125127// given type inside a program. This is a valid assumption when abiding to
......@@ -129,6 +131,7 @@ public:
129131// a deep string comparison.
130132// -------------------------------------------------------------------------- //
131133// NonUnique
134// (_LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION = 2)
132135// -------------------------------------------------------------------------- //
133136// This implementation of type_info does not assume there is always a unique
134137// copy of the RTTI for a given type inside a program. For various reasons
......@@ -138,6 +141,7 @@ public:
138141// comparison is equal.
139142// -------------------------------------------------------------------------- //
140143// NonUniqueARMRTTIBit
144// (selected on ARM64 regardless of _LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION)
141145// -------------------------------------------------------------------------- //
142146// This implementation of type_info does not assume always a unique copy of
143147// the RTTI for a given type inside a program. It packs the pointer to the
......@@ -255,12 +259,12 @@ struct __type_info_implementations {
255259 typedef
256260#if defined(__APPLE__) && defined(__LP64__) && !defined(__x86_64__)
257261 __non_unique_arm_rtti_bit_impl
258#elif _LIBCPP_HAS_MERGED_TYPEINFO_NAMES_DEFAULT == 0
259 __non_unique_impl
260#elif _LIBCPP_HAS_MERGED_TYPEINFO_NAMES_DEFAULT == 1
262#elif _LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION == 1
261263 __unique_impl
264#elif _LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION == 2
265 __non_unique_impl
262266#else
263# error invalid configuration for _LIBCPP_HAS_MERGED_TYPEINFO_NAMES_DEFAULT
267# error invalid configuration for _LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION
264268#endif
265269 __impl;
266270};
......@@ -318,6 +322,7 @@ class _LIBCPP_EXCEPTION_ABI bad_cast
318322{
319323 public:
320324 bad_cast() _NOEXCEPT;
325 bad_cast(const bad_cast&) _NOEXCEPT = default;
321326 virtual ~bad_cast() _NOEXCEPT;
322327 virtual const char* what() const _NOEXCEPT;
323328};
lib/libcxx/include/unordered_map+18-8
......@@ -386,10 +386,12 @@ template <class Key, class T, class Hash, class Pred, class Alloc>
386386 noexcept(noexcept(x.swap(y)));
387387
388388template <class K, class T, class H, class P, class A, class Predicate>
389 void erase_if(unordered_set<K, T, H, P, A>& c, Predicate pred); // C++20
389 typename unordered_map<K, T, H, P, A>::size_type
390 erase_if(unordered_map<K, T, H, P, A>& c, Predicate pred); // C++20
390391
391392template <class K, class T, class H, class P, class A, class Predicate>
392 void erase_if(unordered_multiset<K, T, H, P, A>& c, Predicate pred); // C++20
393 typename unordered_multimap<K, T, H, P, A>::size_type
394 erase_if(unordered_multimap<K, T, H, P, A>& c, Predicate pred); // C++20
393395
394396template <class Key, class T, class Hash, class Pred, class Alloc>
395397 bool
......@@ -1704,10 +1706,14 @@ swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
17041706}
17051707
17061708#if _LIBCPP_STD_VER > 17
1707template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc, class _Predicate>
1709template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc,
1710 class _Predicate>
17081711inline _LIBCPP_INLINE_VISIBILITY
1709void erase_if(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __c, _Predicate __pred)
1710{ __libcpp_erase_if_container(__c, __pred); }
1712 typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::size_type
1713 erase_if(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __c,
1714 _Predicate __pred) {
1715 return __libcpp_erase_if_container(__c, __pred);
1716}
17111717#endif
17121718
17131719template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
......@@ -2402,10 +2408,14 @@ swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
24022408}
24032409
24042410#if _LIBCPP_STD_VER > 17
2405template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc, class _Predicate>
2411template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc,
2412 class _Predicate>
24062413inline _LIBCPP_INLINE_VISIBILITY
2407void erase_if(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __c, _Predicate __pred)
2408{ __libcpp_erase_if_container(__c, __pred); }
2414 typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::size_type
2415 erase_if(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __c,
2416 _Predicate __pred) {
2417 return __libcpp_erase_if_container(__c, __pred);
2418}
24092419#endif
24102420
24112421template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
lib/libcxx/include/unordered_set+18-8
......@@ -341,10 +341,12 @@ template <class Value, class Hash, class Pred, class Alloc>
341341 noexcept(noexcept(x.swap(y)));
342342
343343template <class K, class T, class H, class P, class A, class Predicate>
344 void erase_if(unordered_set<K, T, H, P, A>& c, Predicate pred); // C++20
344 typename unordered_set<K, T, H, P, A>::size_type
345 erase_if(unordered_set<K, T, H, P, A>& c, Predicate pred); // C++20
345346
346347template <class K, class T, class H, class P, class A, class Predicate>
347 void erase_if(unordered_multiset<K, T, H, P, A>& c, Predicate pred); // C++20
348 typename unordered_multiset<K, T, H, P, A>::size_type
349 erase_if(unordered_multiset<K, T, H, P, A>& c, Predicate pred); // C++20
348350
349351
350352template <class Value, class Hash, class Pred, class Alloc>
......@@ -1006,10 +1008,14 @@ swap(unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
10061008}
10071009
10081010#if _LIBCPP_STD_VER > 17
1009template <class _Value, class _Hash, class _Pred, class _Alloc, class _Predicate>
1011template <class _Value, class _Hash, class _Pred, class _Alloc,
1012 class _Predicate>
10101013inline _LIBCPP_INLINE_VISIBILITY
1011void erase_if(unordered_set<_Value, _Hash, _Pred, _Alloc>& __c, _Predicate __pred)
1012{ __libcpp_erase_if_container(__c, __pred); }
1014 typename unordered_set<_Value, _Hash, _Pred, _Alloc>::size_type
1015 erase_if(unordered_set<_Value, _Hash, _Pred, _Alloc>& __c,
1016 _Predicate __pred) {
1017 return __libcpp_erase_if_container(__c, __pred);
1018}
10131019#endif
10141020
10151021template <class _Value, class _Hash, class _Pred, class _Alloc>
......@@ -1637,10 +1643,14 @@ swap(unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
16371643}
16381644
16391645#if _LIBCPP_STD_VER > 17
1640template <class _Value, class _Hash, class _Pred, class _Alloc, class _Predicate>
1646template <class _Value, class _Hash, class _Pred, class _Alloc,
1647 class _Predicate>
16411648inline _LIBCPP_INLINE_VISIBILITY
1642void erase_if(unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __c, _Predicate __pred)
1643{ __libcpp_erase_if_container(__c, __pred); }
1649 typename unordered_multiset<_Value, _Hash, _Pred, _Alloc>::size_type
1650 erase_if(unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __c,
1651 _Predicate __pred) {
1652 return __libcpp_erase_if_container(__c, __pred);
1653}
16441654#endif
16451655
16461656template <class _Value, class _Hash, class _Pred, class _Alloc>
lib/libcxx/include/variant+14-8
......@@ -1063,18 +1063,24 @@ public:
10631063 }
10641064 __impl __tmp(_VSTD::move(*__rhs));
10651065#ifndef _LIBCPP_NO_EXCEPTIONS
1066 // EXTENSION: When the move construction of `__lhs` into `__rhs` throws
1067 // and `__tmp` is nothrow move constructible then we move `__tmp` back
1068 // into `__rhs` and provide the strong exception safety guarantee.
1069 try {
1066 if constexpr (__all<is_nothrow_move_constructible_v<_Types>...>::value) {
10701067 this->__generic_construct(*__rhs, _VSTD::move(*__lhs));
1071 } catch (...) {
1072 if (__tmp.__move_nothrow()) {
1073 this->__generic_construct(*__rhs, _VSTD::move(__tmp));
1068 } else {
1069 // EXTENSION: When the move construction of `__lhs` into `__rhs` throws
1070 // and `__tmp` is nothrow move constructible then we move `__tmp` back
1071 // into `__rhs` and provide the strong exception safety guarantee.
1072 try {
1073 this->__generic_construct(*__rhs, _VSTD::move(*__lhs));
1074 } catch (...) {
1075 if (__tmp.__move_nothrow()) {
1076 this->__generic_construct(*__rhs, _VSTD::move(__tmp));
1077 }
1078 throw;
10741079 }
1075 throw;
10761080 }
10771081#else
1082 // this isn't consolidated with the `if constexpr` branch above due to
1083 // `throw` being ill-formed with exceptions disabled even when discarded.
10781084 this->__generic_construct(*__rhs, _VSTD::move(*__lhs));
10791085#endif
10801086 this->__generic_construct(*__lhs, _VSTD::move(__tmp));
lib/libcxx/include/vector+27-16
......@@ -261,9 +261,11 @@ void swap(vector<T,Allocator>& x, vector<T,Allocator>& y)
261261 noexcept(noexcept(x.swap(y)));
262262
263263template <class T, class Allocator, class U>
264 void erase(vector<T, Allocator>& c, const U& value); // C++20
264typename vector<T, Allocator>::size_type
265erase(vector<T, Allocator>& c, const U& value); // C++20
265266template <class T, class Allocator, class Predicate>
266 void erase_if(vector<T, Allocator>& c, Predicate pred); // C++20
267typename vector<T, Allocator>::size_type
268erase_if(vector<T, Allocator>& c, Predicate pred); // C++20
267269
268270} // std
269271
......@@ -1041,8 +1043,9 @@ void
10411043vector<_Tp, _Allocator>::__construct_at_end(size_type __n)
10421044{
10431045 _ConstructTransaction __tx(*this, __n);
1044 for (; __tx.__pos_ != __tx.__new_end_; ++__tx.__pos_) {
1045 __alloc_traits::construct(this->__alloc(), _VSTD::__to_address(__tx.__pos_));
1046 const_pointer __new_end = __tx.__new_end_;
1047 for (pointer __pos = __tx.__pos_; __pos != __new_end; ++__pos, __tx.__pos_ = __pos) {
1048 __alloc_traits::construct(this->__alloc(), _VSTD::__to_address(__pos));
10461049 }
10471050}
10481051
......@@ -1058,8 +1061,9 @@ void
10581061vector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x)
10591062{
10601063 _ConstructTransaction __tx(*this, __n);
1061 for (; __tx.__pos_ != __tx.__new_end_; ++__tx.__pos_) {
1062 __alloc_traits::construct(this->__alloc(), _VSTD::__to_address(__tx.__pos_), __x);
1064 const_pointer __new_end = __tx.__new_end_;
1065 for (pointer __pos = __tx.__pos_; __pos != __new_end; ++__pos, __tx.__pos_ = __pos) {
1066 __alloc_traits::construct(this->__alloc(), _VSTD::__to_address(__pos), __x);
10631067 }
10641068}
10651069
......@@ -1751,9 +1755,10 @@ vector<_Tp, _Allocator>::__move_range(pointer __from_s, pointer __from_e, pointe
17511755 {
17521756 pointer __i = __from_s + __n;
17531757 _ConstructTransaction __tx(*this, __from_e - __i);
1754 for (; __i < __from_e; ++__i, ++__tx.__pos_) {
1758 for (pointer __pos = __tx.__pos_; __i < __from_e;
1759 ++__i, ++__pos, __tx.__pos_ = __pos) {
17551760 __alloc_traits::construct(this->__alloc(),
1756 _VSTD::__to_address(__tx.__pos_),
1761 _VSTD::__to_address(__pos),
17571762 _VSTD::move(*__i));
17581763 }
17591764 }
......@@ -1956,8 +1961,8 @@ vector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __firs
19561961#endif // _LIBCPP_NO_EXCEPTIONS
19571962 }
19581963 __p = _VSTD::rotate(__p, __old_last, this->__end_);
1959 insert(__make_iter(__p), make_move_iterator(__v.begin()),
1960 make_move_iterator(__v.end()));
1964 insert(__make_iter(__p), _VSTD::make_move_iterator(__v.begin()),
1965 _VSTD::make_move_iterator(__v.end()));
19611966 return begin() + __off;
19621967}
19631968
......@@ -3389,14 +3394,20 @@ swap(vector<_Tp, _Allocator>& __x, vector<_Tp, _Allocator>& __y)
33893394
33903395#if _LIBCPP_STD_VER > 17
33913396template <class _Tp, class _Allocator, class _Up>
3392inline _LIBCPP_INLINE_VISIBILITY
3393void erase(vector<_Tp, _Allocator>& __c, const _Up& __v)
3394{ __c.erase(_VSTD::remove(__c.begin(), __c.end(), __v), __c.end()); }
3397inline _LIBCPP_INLINE_VISIBILITY typename vector<_Tp, _Allocator>::size_type
3398erase(vector<_Tp, _Allocator>& __c, const _Up& __v) {
3399 auto __old_size = __c.size();
3400 __c.erase(_VSTD::remove(__c.begin(), __c.end(), __v), __c.end());
3401 return __old_size - __c.size();
3402}
33953403
33963404template <class _Tp, class _Allocator, class _Predicate>
3397inline _LIBCPP_INLINE_VISIBILITY
3398void erase_if(vector<_Tp, _Allocator>& __c, _Predicate __pred)
3399{ __c.erase(_VSTD::remove_if(__c.begin(), __c.end(), __pred), __c.end()); }
3405inline _LIBCPP_INLINE_VISIBILITY typename vector<_Tp, _Allocator>::size_type
3406erase_if(vector<_Tp, _Allocator>& __c, _Predicate __pred) {
3407 auto __old_size = __c.size();
3408 __c.erase(_VSTD::remove_if(__c.begin(), __c.end(), __pred), __c.end());
3409 return __old_size - __c.size();
3410}
34003411#endif
34013412
34023413_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/version+16-5
......@@ -21,7 +21,8 @@ __cpp_lib_allocator_traits_is_always_equal 201411L <memory> <scoped
2121 <unordered_map> <unordered_set>
2222__cpp_lib_any 201606L <any>
2323__cpp_lib_apply 201603L <tuple>
24__cpp_lib_array_constexpr 201603L <iterator> <array>
24__cpp_lib_array_constexpr 201811L <iterator> <array>
25 201603L // C++17
2526__cpp_lib_as_const 201510L <utility>
2627__cpp_lib_atomic_is_always_lock_free 201603L <atomic>
2728__cpp_lib_atomic_ref 201806L <atomic>
......@@ -44,7 +45,7 @@ __cpp_lib_constexpr_swap_algorithms 201806L <algorithm>
4445__cpp_lib_destroying_delete 201806L <new>
4546__cpp_lib_enable_shared_from_this 201603L <memory>
4647__cpp_lib_endian 201907L <bit>
47__cpp_lib_erase_if 201811L <string> <deque> <forward_list>
48__cpp_lib_erase_if 202002L <string> <deque> <forward_list>
4849 <list> <vector> <map>
4950 <set> <unordered_map> <unordered_set>
5051__cpp_lib_exchange_function 201304L <utility>
......@@ -74,6 +75,7 @@ __cpp_lib_make_from_tuple 201606L <tuple>
7475__cpp_lib_make_reverse_iterator 201402L <iterator>
7576__cpp_lib_make_unique 201304L <memory>
7677__cpp_lib_map_try_emplace 201411L <map>
78__cpp_lib_math_constants 201907L <numbers>
7779__cpp_lib_math_special_functions 201603L <cmath>
7880__cpp_lib_memory_resource 201603L <memory_resource>
7981__cpp_lib_node_extract 201606L <map> <set> <unordered_map>
......@@ -98,9 +100,11 @@ __cpp_lib_shared_mutex 201505L <shared_mutex>
98100__cpp_lib_shared_ptr_arrays 201611L <memory>
99101__cpp_lib_shared_ptr_weak_type 201606L <memory>
100102__cpp_lib_shared_timed_mutex 201402L <shared_mutex>
103__cpp_lib_span 202002L <span>
101104__cpp_lib_string_udls 201304L <string>
102105__cpp_lib_string_view 201606L <string> <string_view>
103106__cpp_lib_three_way_comparison 201711L <compare>
107__cpp_lib_to_array 201907L <array>
104108__cpp_lib_to_chars 201611L <utility>
105109__cpp_lib_transformation_trait_aliases 201304L <type_traits>
106110__cpp_lib_transparent_operators 201510L <functional>
......@@ -167,7 +171,7 @@ __cpp_lib_void_t 201411L <type_traits>
167171// # define __cpp_lib_execution 201603L
168172# define __cpp_lib_filesystem 201703L
169173# define __cpp_lib_gcd_lcm 201606L
170# define __cpp_lib_hardware_interference_size 201703L
174// # define __cpp_lib_hardware_interference_size 201703L
171175# if defined(_LIBCPP_HAS_UNIQUE_OBJECT_REPRESENTATIONS)
172176# define __cpp_lib_has_unique_object_representations 201606L
173177# endif
......@@ -210,6 +214,8 @@ __cpp_lib_void_t 201411L <type_traits>
210214#endif
211215
212216#if _LIBCPP_STD_VER > 17
217# undef __cpp_lib_array_constexpr
218# define __cpp_lib_array_constexpr 201811L
213219# if !defined(_LIBCPP_HAS_NO_THREADS)
214220// # define __cpp_lib_atomic_ref 201806L
215221# endif
......@@ -225,15 +231,20 @@ __cpp_lib_void_t 201411L <type_traits>
225231# define __cpp_lib_destroying_delete 201806L
226232# endif
227233# define __cpp_lib_endian 201907L
228# define __cpp_lib_erase_if 201811L
234# define __cpp_lib_erase_if 202002L
229235// # define __cpp_lib_generic_unordered_lookup 201811L
230236# define __cpp_lib_interpolate 201902L
231237# if !defined(_LIBCPP_HAS_NO_BUILTIN_IS_CONSTANT_EVALUATED)
232238# define __cpp_lib_is_constant_evaluated 201811L
233239# endif
234// # define __cpp_lib_list_remove_return_type 201806L
240# define __cpp_lib_list_remove_return_type 201806L
241# if defined(__cpp_concepts) && __cpp_concepts >= 201811L
242# define __cpp_lib_math_constants 201907L
243# endif
235244// # define __cpp_lib_ranges 201811L
245# define __cpp_lib_span 202002L
236246// # define __cpp_lib_three_way_comparison 201711L
247# define __cpp_lib_to_array 201907L
237248#endif
238249
239250#endif // _LIBCPP_VERSIONH
lib/libcxx/include/wchar.h+1
......@@ -106,6 +106,7 @@ size_t wcsrtombs(char* restrict dst, const wchar_t** restrict src, size_t len,
106106*/
107107
108108#include <__config>
109#include <stddef.h>
109110
110111#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
111112#pragma GCC system_header
lib/libcxx/src/algorithm.cpp-48
......@@ -7,13 +7,6 @@
77//===----------------------------------------------------------------------===//
88
99#include "algorithm"
10#include "random"
11#ifndef _LIBCPP_HAS_NO_THREADS
12#include "mutex"
13#if defined(__ELF__) && defined(_LIBCPP_LINK_PTHREAD_LIB)
14#pragma comment(lib, "pthread")
15#endif
16#endif
1710
1811_LIBCPP_BEGIN_NAMESPACE_STD
1912
......@@ -51,45 +44,4 @@ template bool __insertion_sort_incomplete<__less<long double>&, long double*>(lo
5144
5245template unsigned __sort5<__less<long double>&, long double*>(long double*, long double*, long double*, long double*, long double*, __less<long double>&);
5346
54#ifndef _LIBCPP_HAS_NO_THREADS
55_LIBCPP_SAFE_STATIC static __libcpp_mutex_t __rs_mut = _LIBCPP_MUTEX_INITIALIZER;
56#endif
57unsigned __rs_default::__c_ = 0;
58
59__rs_default::__rs_default()
60{
61#ifndef _LIBCPP_HAS_NO_THREADS
62 __libcpp_mutex_lock(&__rs_mut);
63#endif
64 __c_ = 1;
65}
66
67__rs_default::__rs_default(const __rs_default&)
68{
69 ++__c_;
70}
71
72__rs_default::~__rs_default()
73{
74#ifndef _LIBCPP_HAS_NO_THREADS
75 if (--__c_ == 0)
76 __libcpp_mutex_unlock(&__rs_mut);
77#else
78 --__c_;
79#endif
80}
81
82__rs_default::result_type
83__rs_default::operator()()
84{
85 static mt19937 __rs_g;
86 return __rs_g();
87}
88
89__rs_default
90__rs_get()
91{
92 return __rs_default();
93}
94
9547_LIBCPP_END_NAMESPACE_STD
lib/libcxx/src/atomic.cpp created+189
......@@ -0,0 +1,189 @@
1//===------------------------- atomic.cpp ---------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
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#ifndef _LIBCPP_HAS_NO_THREADS
11
12#include <climits>
13#include <atomic>
14#include <functional>
15
16#include <iostream>
17
18#ifdef __linux__
19
20#include <unistd.h>
21#include <linux/futex.h>
22#include <sys/syscall.h>
23
24#else // <- Add other operating systems here
25
26// Baseline needs no new headers
27
28#endif
29
30_LIBCPP_BEGIN_NAMESPACE_STD
31
32#ifdef __linux__
33
34static void __libcpp_platform_wait_on_address(__cxx_atomic_contention_t const volatile* __ptr,
35 __cxx_contention_t __val)
36{
37 static constexpr timespec __timeout = { 2, 0 };
38 syscall(SYS_futex, __ptr, FUTEX_WAIT_PRIVATE, __val, &__timeout, 0, 0);
39}
40
41static void __libcpp_platform_wake_by_address(__cxx_atomic_contention_t const volatile* __ptr,
42 bool __notify_one)
43{
44 syscall(SYS_futex, __ptr, FUTEX_WAKE_PRIVATE, __notify_one ? 1 : INT_MAX, 0, 0, 0);
45}
46
47#elif defined(__APPLE__) && defined(_LIBCPP_USE_ULOCK)
48
49extern "C" int __ulock_wait(uint32_t operation, void *addr, uint64_t value,
50 uint32_t timeout); /* timeout is specified in microseconds */
51extern "C" int __ulock_wake(uint32_t operation, void *addr, uint64_t wake_value);
52
53#define UL_COMPARE_AND_WAIT 1
54#define ULF_WAKE_ALL 0x00000100
55
56static void __libcpp_platform_wait_on_address(__cxx_atomic_contention_t const volatile* __ptr,
57 __cxx_contention_t __val)
58{
59 __ulock_wait(UL_COMPARE_AND_WAIT,
60 const_cast<__cxx_atomic_contention_t*>(__ptr), __val, 0);
61}
62
63static void __libcpp_platform_wake_by_address(__cxx_atomic_contention_t const volatile* __ptr,
64 bool __notify_one)
65{
66 __ulock_wake(UL_COMPARE_AND_WAIT | (__notify_one ? 0 : ULF_WAKE_ALL),
67 const_cast<__cxx_atomic_contention_t*>(__ptr), 0);
68}
69
70#else // <- Add other operating systems here
71
72// Baseline is just a timed backoff
73
74static void __libcpp_platform_wait_on_address(__cxx_atomic_contention_t const volatile* __ptr,
75 __cxx_contention_t __val)
76{
77 __libcpp_thread_poll_with_backoff([=]() -> bool {
78 return !__cxx_nonatomic_compare_equal(__cxx_atomic_load(__ptr, memory_order_relaxed), __val);
79 }, __libcpp_timed_backoff_policy());
80}
81
82static void __libcpp_platform_wake_by_address(__cxx_atomic_contention_t const volatile*, bool) { }
83
84#endif // __linux__
85
86static constexpr size_t __libcpp_contention_table_size = (1 << 8); /* < there's no magic in this number */
87
88struct alignas(64) /* aim to avoid false sharing */ __libcpp_contention_table_entry
89{
90 __cxx_atomic_contention_t __contention_state;
91 __cxx_atomic_contention_t __platform_state;
92 inline constexpr __libcpp_contention_table_entry() :
93 __contention_state(0), __platform_state(0) { }
94};
95
96static __libcpp_contention_table_entry __libcpp_contention_table[ __libcpp_contention_table_size ];
97
98static hash<void const volatile*> __libcpp_contention_hasher;
99
100static __libcpp_contention_table_entry* __libcpp_contention_state(void const volatile * p)
101{
102 return &__libcpp_contention_table[__libcpp_contention_hasher(p) & (__libcpp_contention_table_size - 1)];
103}
104
105/* Given an atomic to track contention and an atomic to actually wait on, which may be
106 the same atomic, we try to detect contention to avoid spuriously calling the platform. */
107
108static void __libcpp_contention_notify(__cxx_atomic_contention_t volatile* __contention_state,
109 __cxx_atomic_contention_t const volatile* __platform_state,
110 bool __notify_one)
111{
112 if(0 != __cxx_atomic_load(__contention_state, memory_order_seq_cst))
113 // We only call 'wake' if we consumed a contention bit here.
114 __libcpp_platform_wake_by_address(__platform_state, __notify_one);
115}
116static __cxx_contention_t __libcpp_contention_monitor_for_wait(__cxx_atomic_contention_t volatile* __contention_state,
117 __cxx_atomic_contention_t const volatile* __platform_state)
118{
119 // We will monitor this value.
120 return __cxx_atomic_load(__platform_state, memory_order_acquire);
121}
122static void __libcpp_contention_wait(__cxx_atomic_contention_t volatile* __contention_state,
123 __cxx_atomic_contention_t const volatile* __platform_state,
124 __cxx_contention_t __old_value)
125{
126 __cxx_atomic_fetch_add(__contention_state, __cxx_contention_t(1), memory_order_seq_cst);
127 // We sleep as long as the monitored value hasn't changed.
128 __libcpp_platform_wait_on_address(__platform_state, __old_value);
129 __cxx_atomic_fetch_sub(__contention_state, __cxx_contention_t(1), memory_order_release);
130}
131
132/* When the incoming atomic is the wrong size for the platform wait size, need to
133 launder the value sequence through an atomic from our table. */
134
135static void __libcpp_atomic_notify(void const volatile* __location)
136{
137 auto const __entry = __libcpp_contention_state(__location);
138 // The value sequence laundering happens on the next line below.
139 __cxx_atomic_fetch_add(&__entry->__platform_state, __cxx_contention_t(1), memory_order_release);
140 __libcpp_contention_notify(&__entry->__contention_state,
141 &__entry->__platform_state,
142 false /* when laundering, we can't handle notify_one */);
143}
144_LIBCPP_EXPORTED_FROM_ABI
145void __cxx_atomic_notify_one(void const volatile* __location)
146 { __libcpp_atomic_notify(__location); }
147_LIBCPP_EXPORTED_FROM_ABI
148void __cxx_atomic_notify_all(void const volatile* __location)
149 { __libcpp_atomic_notify(__location); }
150_LIBCPP_EXPORTED_FROM_ABI
151__cxx_contention_t __libcpp_atomic_monitor(void const volatile* __location)
152{
153 auto const __entry = __libcpp_contention_state(__location);
154 return __libcpp_contention_monitor_for_wait(&__entry->__contention_state, &__entry->__platform_state);
155}
156_LIBCPP_EXPORTED_FROM_ABI
157void __libcpp_atomic_wait(void const volatile* __location, __cxx_contention_t __old_value)
158{
159 auto const __entry = __libcpp_contention_state(__location);
160 __libcpp_contention_wait(&__entry->__contention_state, &__entry->__platform_state, __old_value);
161}
162
163/* When the incoming atomic happens to be the platform wait size, we still need to use the
164 table for the contention detection, but we can use the atomic directly for the wait. */
165
166_LIBCPP_EXPORTED_FROM_ABI
167void __cxx_atomic_notify_one(__cxx_atomic_contention_t const volatile* __location)
168{
169 __libcpp_contention_notify(&__libcpp_contention_state(__location)->__contention_state, __location, true);
170}
171_LIBCPP_EXPORTED_FROM_ABI
172void __cxx_atomic_notify_all(__cxx_atomic_contention_t const volatile* __location)
173{
174 __libcpp_contention_notify(&__libcpp_contention_state(__location)->__contention_state, __location, false);
175}
176_LIBCPP_EXPORTED_FROM_ABI
177__cxx_contention_t __libcpp_atomic_monitor(__cxx_atomic_contention_t const volatile* __location)
178{
179 return __libcpp_contention_monitor_for_wait(&__libcpp_contention_state(__location)->__contention_state, __location);
180}
181_LIBCPP_EXPORTED_FROM_ABI
182void __libcpp_atomic_wait(__cxx_atomic_contention_t const volatile* __location, __cxx_contention_t __old_value)
183{
184 __libcpp_contention_wait(&__libcpp_contention_state(__location)->__contention_state, __location, __old_value);
185}
186
187_LIBCPP_END_NAMESPACE_STD
188
189#endif //_LIBCPP_HAS_NO_THREADS
lib/libcxx/src/barrier.cpp created+103
......@@ -0,0 +1,103 @@
1//===------------------------- barrier.cpp ---------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
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
11#ifndef _LIBCPP_HAS_NO_THREADS
12
13#include <barrier>
14#include <thread>
15
16_LIBCPP_BEGIN_NAMESPACE_STD
17
18#if !defined(_LIBCPP_HAS_NO_TREE_BARRIER) && (_LIBCPP_STD_VER > 11)
19
20class __barrier_algorithm_base {
21public:
22 struct alignas(64) /* naturally-align the heap state */ __state_t
23 {
24 struct {
25 __atomic_base<__barrier_phase_t> __phase = ATOMIC_VAR_INIT(0);
26 } __tickets[64];
27 };
28
29 ptrdiff_t& __expected;
30 unique_ptr<char[]> __state_allocation;
31 __state_t* __state;
32
33 _LIBCPP_HIDDEN
34 __barrier_algorithm_base(ptrdiff_t& __expected)
35 : __expected(__expected)
36 {
37 size_t const __count = (__expected + 1) >> 1;
38 size_t const __size = sizeof(__state_t) * __count;
39 size_t __allocation_size = __size + alignof(__state_t);
40 __state_allocation = unique_ptr<char[]>(new char[__allocation_size]);
41 void* __allocation = __state_allocation.get();
42 void* const __state_ = align(alignof(__state_t), __size, __allocation, __allocation_size);
43 __state = new (__state_) __barrier_algorithm_base::__state_t[__count];
44 }
45 _LIBCPP_HIDDEN
46 bool __arrive(__barrier_phase_t __old_phase)
47 {
48 __barrier_phase_t const __half_step = __old_phase + 1,
49 __full_step = __old_phase + 2;
50 size_t __current_expected = __expected,
51 __current = hash<thread::id>()(this_thread::get_id()) % ((__expected + 1) >> 1);
52 for(int __round = 0;; ++__round) {
53 if(__current_expected <= 1)
54 return true;
55 size_t const __end_node = ((__current_expected + 1) >> 1),
56 __last_node = __end_node - 1;
57 for(;;++__current) {
58 if(__current == __end_node)
59 __current = 0;
60 __barrier_phase_t expect = __old_phase;
61 if(__current == __last_node && (__current_expected & 1))
62 {
63 if(__state[__current].__tickets[__round].__phase.compare_exchange_strong(expect, __full_step, memory_order_acq_rel))
64 break; // I'm 1 in 1, go to next __round
65 }
66 else if(__state[__current].__tickets[__round].__phase.compare_exchange_strong(expect, __half_step, memory_order_acq_rel))
67 {
68 return false; // I'm 1 in 2, done with arrival
69 }
70 else if(expect == __half_step)
71 {
72 if(__state[__current].__tickets[__round].__phase.compare_exchange_strong(expect, __full_step, memory_order_acq_rel))
73 break; // I'm 2 in 2, go to next __round
74 }
75 }
76 __current_expected = __last_node + 1;
77 __current >>= 1;
78 }
79 }
80};
81
82_LIBCPP_EXPORTED_FROM_ABI
83__barrier_algorithm_base * __construct_barrier_algorithm_base(ptrdiff_t& __expected)
84{
85 return new __barrier_algorithm_base(__expected);
86}
87_LIBCPP_EXPORTED_FROM_ABI
88bool __arrive_barrier_algorithm_base(__barrier_algorithm_base* __barrier,
89 __barrier_phase_t __old_phase)
90{
91 return __barrier->__arrive(__old_phase);
92}
93_LIBCPP_EXPORTED_FROM_ABI
94void __destroy_barrier_algorithm_base(__barrier_algorithm_base* __barrier)
95{
96 delete __barrier;
97}
98
99#endif //!defined(_LIBCPP_HAS_NO_TREE_BARRIER) && (_LIBCPP_STD_VER >= 11)
100
101_LIBCPP_END_NAMESPACE_STD
102
103#endif //_LIBCPP_HAS_NO_THREADS
lib/libcxx/src/charconv.cpp+9-9
......@@ -32,7 +32,7 @@ static constexpr char cDigitsLut[200] = {
3232
3333template <typename T>
3434inline _LIBCPP_INLINE_VISIBILITY char*
35append1(char* buffer, T i)
35append1(char* buffer, T i) noexcept
3636{
3737 *buffer = '0' + static_cast<char>(i);
3838 return buffer + 1;
......@@ -40,7 +40,7 @@ append1(char* buffer, T i)
4040
4141template <typename T>
4242inline _LIBCPP_INLINE_VISIBILITY char*
43append2(char* buffer, T i)
43append2(char* buffer, T i) noexcept
4444{
4545 memcpy(buffer, &cDigitsLut[(i)*2], 2);
4646 return buffer + 2;
......@@ -48,21 +48,21 @@ append2(char* buffer, T i)
4848
4949template <typename T>
5050inline _LIBCPP_INLINE_VISIBILITY char*
51append3(char* buffer, T i)
51append3(char* buffer, T i) noexcept
5252{
5353 return append2(append1(buffer, (i) / 100), (i) % 100);
5454}
5555
5656template <typename T>
5757inline _LIBCPP_INLINE_VISIBILITY char*
58append4(char* buffer, T i)
58append4(char* buffer, T i) noexcept
5959{
6060 return append2(append2(buffer, (i) / 100), (i) % 100);
6161}
6262
6363template <typename T>
6464inline _LIBCPP_INLINE_VISIBILITY char*
65append2_no_zeros(char* buffer, T v)
65append2_no_zeros(char* buffer, T v) noexcept
6666{
6767 if (v < 10)
6868 return append1(buffer, v);
......@@ -72,7 +72,7 @@ append2_no_zeros(char* buffer, T v)
7272
7373template <typename T>
7474inline _LIBCPP_INLINE_VISIBILITY char*
75append4_no_zeros(char* buffer, T v)
75append4_no_zeros(char* buffer, T v) noexcept
7676{
7777 if (v < 100)
7878 return append2_no_zeros(buffer, v);
......@@ -84,7 +84,7 @@ append4_no_zeros(char* buffer, T v)
8484
8585template <typename T>
8686inline _LIBCPP_INLINE_VISIBILITY char*
87append8_no_zeros(char* buffer, T v)
87append8_no_zeros(char* buffer, T v) noexcept
8888{
8989 if (v < 10000)
9090 {
......@@ -99,7 +99,7 @@ append8_no_zeros(char* buffer, T v)
9999}
100100
101101char*
102__u32toa(uint32_t value, char* buffer)
102__u32toa(uint32_t value, char* buffer) _NOEXCEPT
103103{
104104 if (value < 100000000)
105105 {
......@@ -120,7 +120,7 @@ __u32toa(uint32_t value, char* buffer)
120120}
121121
122122char*
123__u64toa(uint64_t value, char* buffer)
123__u64toa(uint64_t value, char* buffer) _NOEXCEPT
124124{
125125 if (value < 100000000)
126126 {
lib/libcxx/src/chrono.cpp+31-89
......@@ -9,36 +9,32 @@
99#include "chrono"
1010#include "cerrno" // errno
1111#include "system_error" // __throw_system_error
12#include <time.h> // clock_gettime, CLOCK_MONOTONIC and CLOCK_REALTIME
12#include <time.h> // clock_gettime and CLOCK_{MONOTONIC,REALTIME,MONOTONIC_RAW}
1313#include "include/apple_availability.h"
1414
15#if !defined(__APPLE__)
15#if __has_include(<unistd.h>)
16#include <unistd.h>
17#endif
18
19#if !defined(__APPLE__) && _POSIX_TIMERS > 0
1620#define _LIBCPP_USE_CLOCK_GETTIME
17#endif // __APPLE__
21#endif
1822
1923#if defined(_LIBCPP_WIN32API)
20#define WIN32_LEAN_AND_MEAN
21#define VC_EXTRA_LEAN
22#include <windows.h>
23#if _WIN32_WINNT >= _WIN32_WINNT_WIN8
24#include <winapifamily.h>
25#endif
24# define WIN32_LEAN_AND_MEAN
25# define VC_EXTRA_LEAN
26# include <windows.h>
27# if _WIN32_WINNT >= _WIN32_WINNT_WIN8
28# include <winapifamily.h>
29# endif
2630#else
27#if !defined(CLOCK_REALTIME) || !defined(_LIBCPP_USE_CLOCK_GETTIME)
28#include <sys/time.h> // for gettimeofday and timeval
29#endif // !defined(CLOCK_REALTIME)
31# if !defined(CLOCK_REALTIME)
32# include <sys/time.h> // for gettimeofday and timeval
33# endif // !defined(CLOCK_REALTIME)
3034#endif // defined(_LIBCPP_WIN32API)
3135
32#if !defined(_LIBCPP_HAS_NO_MONOTONIC_CLOCK)
33#if __APPLE__
34#include <mach/mach_time.h> // mach_absolute_time, mach_timebase_info_data_t
35#elif !defined(_LIBCPP_WIN32API) && !defined(CLOCK_MONOTONIC)
36#error "Monotonic clock not implemented"
37#endif
38#endif
39
4036#if defined(__ELF__) && defined(_LIBCPP_LINK_RT_LIB)
41#pragma comment(lib, "rt")
37# pragma comment(lib, "rt")
4238#endif
4339
4440_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -78,7 +74,7 @@ system_clock::now() _NOEXCEPT
7874 static_cast<__int64>(ft.dwLowDateTime)};
7975 return time_point(duration_cast<duration>(d - nt_to_unix_epoch));
8076#else
81#if defined(_LIBCPP_USE_CLOCK_GETTIME) && defined(CLOCK_REALTIME)
77#if defined(CLOCK_REALTIME)
8278 struct timespec tp;
8379 if (0 != clock_gettime(CLOCK_REALTIME, &tp))
8480 __throw_system_error(errno, "clock_gettime(CLOCK_REALTIME) failed");
......@@ -87,7 +83,7 @@ system_clock::now() _NOEXCEPT
8783 timeval tv;
8884 gettimeofday(&tv, 0);
8985 return time_point(seconds(tv.tv_sec) + microseconds(tv.tv_usec));
90#endif // _LIBCPP_USE_CLOCK_GETTIME && CLOCK_REALTIME
86#endif // CLOCK_REALTIME
9187#endif
9288}
9389
......@@ -114,71 +110,24 @@ const bool steady_clock::is_steady;
114110
115111#if defined(__APPLE__)
116112
117// Darwin libc versions >= 1133 provide ns precision via CLOCK_UPTIME_RAW
118#if defined(_LIBCPP_USE_CLOCK_GETTIME) && defined(CLOCK_UPTIME_RAW)
113#if !defined(CLOCK_MONOTONIC_RAW)
114# error "Building libc++ on Apple platforms requires CLOCK_MONOTONIC_RAW"
115#endif
116
117// On Apple platforms, only CLOCK_UPTIME_RAW, CLOCK_MONOTONIC_RAW or
118// mach_absolute_time are able to time functions in the nanosecond range.
119// Furthermore, only CLOCK_MONOTONIC_RAW is truly monotonic, because it
120// also counts cycles when the system is asleep. Thus, it is the only
121// acceptable implementation of steady_clock.
119122steady_clock::time_point
120123steady_clock::now() _NOEXCEPT
121124{
122125 struct timespec tp;
123 if (0 != clock_gettime(CLOCK_UPTIME_RAW, &tp))
124 __throw_system_error(errno, "clock_gettime(CLOCK_UPTIME_RAW) failed");
126 if (0 != clock_gettime(CLOCK_MONOTONIC_RAW, &tp))
127 __throw_system_error(errno, "clock_gettime(CLOCK_MONOTONIC_RAW) failed");
125128 return time_point(seconds(tp.tv_sec) + nanoseconds(tp.tv_nsec));
126129}
127130
128#else
129// mach_absolute_time() * MachInfo.numer / MachInfo.denom is the number of
130// nanoseconds since the computer booted up. MachInfo.numer and MachInfo.denom
131// are run time constants supplied by the OS. This clock has no relationship
132// to the Gregorian calendar. It's main use is as a high resolution timer.
133
134// MachInfo.numer / MachInfo.denom is often 1 on the latest equipment. Specialize
135// for that case as an optimization.
136
137static
138steady_clock::rep
139steady_simplified()
140{
141 return static_cast<steady_clock::rep>(mach_absolute_time());
142}
143
144static
145double
146compute_steady_factor()
147{
148 mach_timebase_info_data_t MachInfo;
149 mach_timebase_info(&MachInfo);
150 return static_cast<double>(MachInfo.numer) / MachInfo.denom;
151}
152
153static
154steady_clock::rep
155steady_full()
156{
157 static const double factor = compute_steady_factor();
158 return static_cast<steady_clock::rep>(mach_absolute_time() * factor);
159}
160
161typedef steady_clock::rep (*FP)();
162
163static
164FP
165init_steady_clock()
166{
167 mach_timebase_info_data_t MachInfo;
168 mach_timebase_info(&MachInfo);
169 if (MachInfo.numer == MachInfo.denom)
170 return &steady_simplified;
171 return &steady_full;
172}
173
174steady_clock::time_point
175steady_clock::now() _NOEXCEPT
176{
177 static FP fp = init_steady_clock();
178 return time_point(duration(fp()));
179}
180#endif // defined(_LIBCPP_USE_CLOCK_GETTIME) && defined(CLOCK_UPTIME_RAW)
181
182131#elif defined(_LIBCPP_WIN32API)
183132
184133// https://msdn.microsoft.com/en-us/library/windows/desktop/ms644905(v=vs.85).aspx says:
......@@ -206,13 +155,6 @@ steady_clock::now() _NOEXCEPT
206155
207156#elif defined(CLOCK_MONOTONIC)
208157
209// On Apple platforms only CLOCK_UPTIME_RAW or mach_absolute_time are able to
210// time functions in the nanosecond range. Thus, they are the only acceptable
211// implementations of steady_clock.
212#ifdef __APPLE__
213#error "Never use CLOCK_MONOTONIC for steady_clock::now on Apple platforms"
214#endif
215
216158steady_clock::time_point
217159steady_clock::now() _NOEXCEPT
218160{
......@@ -223,7 +165,7 @@ steady_clock::now() _NOEXCEPT
223165}
224166
225167#else
226#error "Monotonic clock not implemented"
168# error "Monotonic clock not implemented"
227169#endif
228170
229171#endif // !_LIBCPP_HAS_NO_MONOTONIC_CLOCK
lib/libcxx/src/filesystem/int128_builtins.cpp created+54
......@@ -0,0 +1,54 @@
1/*===-- int128_builtins.cpp - Implement __muloti4 --------------------------===
2 *
3 * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 * See https://llvm.org/LICENSE.txt for license information.
5 * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 *
7 * ===----------------------------------------------------------------------===
8 *
9 * This file implements __muloti4, and is stolen from the compiler_rt library.
10 *
11 * FIXME: we steal and re-compile it into filesystem, which uses __int128_t,
12 * and requires this builtin when sanitized. See llvm.org/PR30643
13 *
14 * ===----------------------------------------------------------------------===
15 */
16#include "__config"
17#include "climits"
18
19#if !defined(_LIBCPP_HAS_NO_INT128)
20
21extern "C" __attribute__((no_sanitize("undefined"))) _LIBCPP_FUNC_VIS
22__int128_t __muloti4(__int128_t a, __int128_t b, int* overflow) {
23 const int N = (int)(sizeof(__int128_t) * CHAR_BIT);
24 const __int128_t MIN = (__int128_t)1 << (N - 1);
25 const __int128_t MAX = ~MIN;
26 *overflow = 0;
27 __int128_t result = a * b;
28 if (a == MIN) {
29 if (b != 0 && b != 1)
30 *overflow = 1;
31 return result;
32 }
33 if (b == MIN) {
34 if (a != 0 && a != 1)
35 *overflow = 1;
36 return result;
37 }
38 __int128_t sa = a >> (N - 1);
39 __int128_t abs_a = (a ^ sa) - sa;
40 __int128_t sb = b >> (N - 1);
41 __int128_t abs_b = (b ^ sb) - sb;
42 if (abs_a < 2 || abs_b < 2)
43 return result;
44 if (sa == sb) {
45 if (abs_a > MAX / abs_b)
46 *overflow = 1;
47 } else {
48 if (abs_a > MIN / -abs_b)
49 *overflow = 1;
50 }
51 return result;
52}
53
54#endif
lib/libcxx/src/filesystem/operations.cpp+4-8
......@@ -36,13 +36,9 @@
3636#define _LIBCPP_USE_COPYFILE
3737#endif
3838
39#if !defined(__APPLE__)
40#define _LIBCPP_USE_CLOCK_GETTIME
41#endif
42
43#if !defined(CLOCK_REALTIME) || !defined(_LIBCPP_USE_CLOCK_GETTIME)
39#if !defined(CLOCK_REALTIME)
4440#include <sys/time.h> // for gettimeofday and timeval
45#endif // !defined(CLOCK_REALTIME)
41#endif // !defined(CLOCK_REALTIME)
4642
4743#if defined(__ELF__) && defined(_LIBCPP_LINK_RT_LIB)
4844#pragma comment(lib, "rt")
......@@ -490,7 +486,7 @@ const bool _FilesystemClock::is_steady;
490486
491487_FilesystemClock::time_point _FilesystemClock::now() noexcept {
492488 typedef chrono::duration<rep> __secs;
493#if defined(_LIBCPP_USE_CLOCK_GETTIME) && defined(CLOCK_REALTIME)
489#if defined(CLOCK_REALTIME)
494490 typedef chrono::duration<rep, nano> __nsecs;
495491 struct timespec tp;
496492 if (0 != clock_gettime(CLOCK_REALTIME, &tp))
......@@ -502,7 +498,7 @@ _FilesystemClock::time_point _FilesystemClock::now() noexcept {
502498 timeval tv;
503499 gettimeofday(&tv, 0);
504500 return time_point(__secs(tv.tv_sec) + __microsecs(tv.tv_usec));
505#endif // _LIBCPP_USE_CLOCK_GETTIME && CLOCK_REALTIME
501#endif // CLOCK_REALTIME
506502}
507503
508504filesystem_error::~filesystem_error() {}
lib/libcxx/src/include/apple_availability.h+8-8
......@@ -29,20 +29,20 @@
2929#endif // __ENVIRONMENT_.*_VERSION_MIN_REQUIRED__
3030
3131#if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__)
32#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 101200
33#define _LIBCPP_USE_CLOCK_GETTIME
32#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 101500
33#define _LIBCPP_USE_ULOCK
3434#endif
3535#elif defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__)
36#if __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ >= 100000
37#define _LIBCPP_USE_CLOCK_GETTIME
36#if __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ >= 130000
37#define _LIBCPP_USE_ULOCK
3838#endif
3939#elif defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__)
40#if __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ >= 100000
41#define _LIBCPP_USE_CLOCK_GETTIME
40#if __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ >= 130000
41#define _LIBCPP_USE_ULOCK
4242#endif
4343#elif defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__)
44#if __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ >= 30000
45#define _LIBCPP_USE_CLOCK_GETTIME
44#if __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ >= 60000
45#define _LIBCPP_USE_ULOCK
4646#endif
4747#endif // __ENVIRONMENT_.*_VERSION_MIN_REQUIRED__
4848
lib/libcxx/src/locale.cpp+2-2
......@@ -536,7 +536,7 @@ locale::operator=(const locale& other) _NOEXCEPT
536536
537537locale::locale(const char* name)
538538 : __locale_(name ? new __imp(name)
539 : (__throw_runtime_error("locale constructed with null"), (__imp*)0))
539 : (__throw_runtime_error("locale constructed with null"), nullptr))
540540{
541541 __locale_->__add_shared();
542542}
......@@ -549,7 +549,7 @@ locale::locale(const string& name)
549549
550550locale::locale(const locale& other, const char* name, category c)
551551 : __locale_(name ? new __imp(*other.__locale_, name, c)
552 : (__throw_runtime_error("locale constructed with null"), (__imp*)0))
552 : (__throw_runtime_error("locale constructed with null"), nullptr))
553553{
554554 __locale_->__add_shared();
555555}
lib/libcxx/src/random_shuffle.cpp created+61
......@@ -0,0 +1,61 @@
1//===----------------------- random_shuffle.cpp ---------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
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 "algorithm"
10#include "random"
11#ifndef _LIBCPP_HAS_NO_THREADS
12# include "mutex"
13# if defined(__ELF__) && defined(_LIBCPP_LINK_PTHREAD_LIB)
14# pragma comment(lib, "pthread")
15# endif
16#endif
17
18_LIBCPP_BEGIN_NAMESPACE_STD
19
20#ifndef _LIBCPP_HAS_NO_THREADS
21_LIBCPP_SAFE_STATIC static __libcpp_mutex_t __rs_mut = _LIBCPP_MUTEX_INITIALIZER;
22#endif
23unsigned __rs_default::__c_ = 0;
24
25__rs_default::__rs_default()
26{
27#ifndef _LIBCPP_HAS_NO_THREADS
28 __libcpp_mutex_lock(&__rs_mut);
29#endif
30 __c_ = 1;
31}
32
33__rs_default::__rs_default(const __rs_default&)
34{
35 ++__c_;
36}
37
38__rs_default::~__rs_default()
39{
40#ifndef _LIBCPP_HAS_NO_THREADS
41 if (--__c_ == 0)
42 __libcpp_mutex_unlock(&__rs_mut);
43#else
44 --__c_;
45#endif
46}
47
48__rs_default::result_type
49__rs_default::operator()()
50{
51 static mt19937 __rs_g;
52 return __rs_g();
53}
54
55__rs_default
56__rs_get()
57{
58 return __rs_default();
59}
60
61_LIBCPP_END_NAMESPACE_STD
lib/libcxx/src/string.cpp+7-2
......@@ -20,8 +20,13 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2020
2121template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __basic_string_common<true>;
2222
23template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_string<char>;
24template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_string<wchar_t>;
23#ifdef _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION
24_LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE_DEFINE, char)
25_LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE_DEFINE, wchar_t)
26#else
27_LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE_DEFINE, char)
28_LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE_DEFINE, wchar_t)
29#endif
2530
2631template
2732 string
lib/libcxx/src/thread.cpp+3-3
......@@ -23,9 +23,9 @@
2323# endif
2424#endif // defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
2525
26#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__CloudABI__) || defined(__Fuchsia__) || defined(__wasi__)
27# include <unistd.h>
28#endif // defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__CloudABI__) || defined(__Fuchsia__) || defined(__wasi__)
26#if __has_include(<unistd.h>)
27#include <unistd.h>
28#endif
2929
3030#if defined(__NetBSD__)
3131#pragma weak pthread_create // Do not create libpthread dependency