diff options
author | arcadia-devtools <arcadia-devtools@yandex-team.ru> | 2022-03-24 13:58:08 +0300 |
---|---|---|
committer | arcadia-devtools <arcadia-devtools@yandex-team.ru> | 2022-03-24 13:58:08 +0300 |
commit | 271ac8fd7cc6c125b34b2bce83590db2b2c7e2d7 (patch) | |
tree | 78acf3dc1d8f60371fb158e6d731d22b49afcf56 /contrib/libs | |
parent | d9fd72590079fc40db118f7993267f5fc8d1ce58 (diff) | |
download | ydb-271ac8fd7cc6c125b34b2bce83590db2b2c7e2d7.tar.gz |
intermediate changes
ref:9eb06e5e31eb4c81bc7f55fa295da8edd4e644bb
Diffstat (limited to 'contrib/libs')
37 files changed, 1028 insertions, 321 deletions
diff --git a/contrib/libs/cxxsupp/libcxx/import b/contrib/libs/cxxsupp/libcxx/import index c2f213f437..61add11c2f 100755 --- a/contrib/libs/cxxsupp/libcxx/import +++ b/contrib/libs/cxxsupp/libcxx/import @@ -1,6 +1,6 @@ #!/bin/sh -e -rev=529a7930 +rev=1fe897df output_dir="libcxx-r$rev" if [ -z $1 ] ; then git clone https://github.com/llvm/llvm-project.git --no-checkout "$output_dir/tmp" diff --git a/contrib/libs/cxxsupp/libcxx/include/__config b/contrib/libs/cxxsupp/libcxx/include/__config index 07ebb3b5bc..0bf660a251 100644 --- a/contrib/libs/cxxsupp/libcxx/include/__config +++ b/contrib/libs/cxxsupp/libcxx/include/__config @@ -345,18 +345,43 @@ # define _LIBCPP_SHORT_WCHAR 1 #endif +// Libc++ supports various implementations of std::random_device. +// +// _LIBCPP_USING_DEV_RANDOM +// Read entropy from the given file, by default `/dev/urandom`. +// If a token is provided, it is assumed to be the path to a file +// to read entropy from. This is the default behavior if nothing +// else is specified. This implementation requires storing state +// inside `std::random_device`. +// +// _LIBCPP_USING_ARC4_RANDOM +// Use arc4random(). This allows obtaining random data even when +// using sandboxing mechanisms. On some platforms like Apple, this +// is the recommended source of entropy for user-space programs. +// When this option is used, the token passed to `std::random_device`'s +// constructor *must* be "/dev/urandom" -- anything else is an error. +// +// _LIBCPP_USING_GETENTROPY +// Use getentropy(). +// When this option is used, the token passed to `std::random_device`'s +// constructor *must* be "/dev/urandom" -- anything else is an error. +// +// _LIBCPP_USING_NACL_RANDOM +// NaCl's sandbox (which PNaCl also runs in) doesn't allow filesystem access, +// including accesses to the special files under `/dev`. This implementation +// uses the NaCL syscall `nacl_secure_random_init()` to get entropy. +// When this option is used, the token passed to `std::random_device`'s +// constructor *must* be "/dev/urandom" -- anything else is an error. +// +// _LIBCPP_USING_WIN32_RANDOM +// Use rand_s(), for use on Windows. +// When this option is used, the token passed to `std::random_device`'s +// constructor *must* be "/dev/urandom" -- anything else is an error. #if defined(__OpenBSD__) - // Certain architectures provide arc4random(). Prefer using - // arc4random() over /dev/{u,}random to make it possible to obtain - // random data even when using sandboxing mechanisms such as chroots, - // Capsicum, etc. # define _LIBCPP_USING_ARC4_RANDOM #elif defined(__Fuchsia__) || defined(__wasi__) # define _LIBCPP_USING_GETENTROPY #elif defined(__native_client__) - // NaCl's sandbox (which PNaCl also runs in) doesn't allow filesystem access, - // including accesses to the special files under /dev. C++11's - // std::random_device is instead exposed through a NaCl syscall. # define _LIBCPP_USING_NACL_RANDOM #elif defined(_LIBCPP_WIN32API) # define _LIBCPP_USING_WIN32_RANDOM diff --git a/contrib/libs/cxxsupp/libcxx/include/__config_site.in b/contrib/libs/cxxsupp/libcxx/include/__config_site.in index a8b17ad72b..59ca229812 100644 --- a/contrib/libs/cxxsupp/libcxx/include/__config_site.in +++ b/contrib/libs/cxxsupp/libcxx/include/__config_site.in @@ -35,5 +35,6 @@ #cmakedefine _LIBCPP_HAS_NO_INCOMPLETE_RANGES @_LIBCPP_ABI_DEFINES@ +@_LIBCPP_EXTRA_SITE_DEFINES@ #endif // _LIBCPP_CONFIG_SITE diff --git a/contrib/libs/cxxsupp/libcxx/include/__debug b/contrib/libs/cxxsupp/libcxx/include/__debug index e25039c088..42f6cef4c0 100644 --- a/contrib/libs/cxxsupp/libcxx/include/__debug +++ b/contrib/libs/cxxsupp/libcxx/include/__debug @@ -34,7 +34,7 @@ # define _LIBCPP_DEBUG_ASSERT(x, m) ((void)0) # define _LIBCPP_ASSERT_IMPL(x, m) ((x) ? (void)0 : _VSTD::__libcpp_debug_function(_VSTD::__libcpp_debug_info(__FILE__, __LINE__, #x, m))) #elif _LIBCPP_DEBUG_LEVEL == 2 -# define _LIBCPP_DEBUG_ASSERT(x, m) _LIBCPP_ASSERT(x, m) +# define _LIBCPP_DEBUG_ASSERT(x, m) _LIBCPP_ASSERT(__libcpp_is_constant_evaluated() || (x), m) # define _LIBCPP_ASSERT_IMPL(x, m) ((x) ? (void)0 : _VSTD::__libcpp_debug_function(_VSTD::__libcpp_debug_info(__FILE__, __LINE__, #x, m))) #else # error _LIBCPP_DEBUG_LEVEL must be one of 0, 1, 2 diff --git a/contrib/libs/cxxsupp/libcxx/include/__iterator/advance.h b/contrib/libs/cxxsupp/libcxx/include/__iterator/advance.h index b38540fbe3..43ec8684fc 100644 --- a/contrib/libs/cxxsupp/libcxx/include/__iterator/advance.h +++ b/contrib/libs/cxxsupp/libcxx/include/__iterator/advance.h @@ -69,6 +69,7 @@ void advance(_InputIter& __i, _Distance __orig_n) { namespace ranges { // [range.iter.op.advance] +// TODO(varconst): rename `__advance_fn` to `__fn`. struct __advance_fn final : private __function_like { private: template <class _Tp> diff --git a/contrib/libs/cxxsupp/libcxx/include/__iterator/next.h b/contrib/libs/cxxsupp/libcxx/include/__iterator/next.h index 3054378f7e..97db48733e 100644 --- a/contrib/libs/cxxsupp/libcxx/include/__iterator/next.h +++ b/contrib/libs/cxxsupp/libcxx/include/__iterator/next.h @@ -39,6 +39,7 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 #if !defined(_LIBCPP_HAS_NO_RANGES) namespace ranges { +// TODO(varconst): rename `__next_fn` to `__fn`. struct __next_fn final : private __function_like { _LIBCPP_HIDE_FROM_ABI constexpr explicit __next_fn(__tag __x) noexcept : __function_like(__x) {} diff --git a/contrib/libs/cxxsupp/libcxx/include/__iterator/prev.h b/contrib/libs/cxxsupp/libcxx/include/__iterator/prev.h index 42d836cc1d..7dd27e2920 100644 --- a/contrib/libs/cxxsupp/libcxx/include/__iterator/prev.h +++ b/contrib/libs/cxxsupp/libcxx/include/__iterator/prev.h @@ -38,6 +38,7 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 #if !defined(_LIBCPP_HAS_NO_RANGES) namespace ranges { +// TODO(varconst): rename `__prev_fn` to `__fn`. struct __prev_fn final : private __function_like { _LIBCPP_HIDE_FROM_ABI constexpr explicit __prev_fn(__tag __x) noexcept : __function_like(__x) {} diff --git a/contrib/libs/cxxsupp/libcxx/include/__memory/compressed_pair.h b/contrib/libs/cxxsupp/libcxx/include/__memory/compressed_pair.h index fd1fcbe5bf..fd6d7109f8 100644 --- a/contrib/libs/cxxsupp/libcxx/include/__memory/compressed_pair.h +++ b/contrib/libs/cxxsupp/libcxx/include/__memory/compressed_pair.h @@ -58,10 +58,8 @@ struct __compressed_pair_elem { : __value_(_VSTD::forward<_Args>(_VSTD::get<_Indexes>(__args))...) {} #endif - - _LIBCPP_INLINE_VISIBILITY reference __get() _NOEXCEPT { return __value_; } - _LIBCPP_INLINE_VISIBILITY - const_reference __get() const _NOEXCEPT { return __value_; } + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 reference __get() _NOEXCEPT { return __value_; } + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __get() const _NOEXCEPT { return __value_; } private: _Tp __value_; @@ -97,9 +95,8 @@ struct __compressed_pair_elem<_Tp, _Idx, true> : private _Tp { : __value_type(_VSTD::forward<_Args>(_VSTD::get<_Indexes>(__args))...) {} #endif - _LIBCPP_INLINE_VISIBILITY reference __get() _NOEXCEPT { return *this; } - _LIBCPP_INLINE_VISIBILITY - const_reference __get() const _NOEXCEPT { return *this; } + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 reference __get() _NOEXCEPT { return *this; } + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __get() const _NOEXCEPT { return *this; } }; template <class _T1, class _T2> @@ -143,23 +140,19 @@ public: typename __make_tuple_indices<sizeof...(_Args2)>::type()) {} #endif - _LIBCPP_INLINE_VISIBILITY - typename _Base1::reference first() _NOEXCEPT { + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 typename _Base1::reference first() _NOEXCEPT { return static_cast<_Base1&>(*this).__get(); } - _LIBCPP_INLINE_VISIBILITY - typename _Base1::const_reference first() const _NOEXCEPT { + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename _Base1::const_reference first() const _NOEXCEPT { return static_cast<_Base1 const&>(*this).__get(); } - _LIBCPP_INLINE_VISIBILITY - typename _Base2::reference second() _NOEXCEPT { + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 typename _Base2::reference second() _NOEXCEPT { return static_cast<_Base2&>(*this).__get(); } - _LIBCPP_INLINE_VISIBILITY - typename _Base2::const_reference second() const _NOEXCEPT { + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename _Base2::const_reference second() const _NOEXCEPT { return static_cast<_Base2 const&>(*this).__get(); } @@ -172,11 +165,8 @@ public: return static_cast<_Base2*>(__pair); } - _LIBCPP_INLINE_VISIBILITY - void swap(__compressed_pair& __x) - _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && - __is_nothrow_swappable<_T2>::value) - { + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 void swap(__compressed_pair& __x) + _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && __is_nothrow_swappable<_T2>::value) { using _VSTD::swap; swap(first(), __x.first()); swap(second(), __x.second()); @@ -184,10 +174,9 @@ public: }; template <class _T1, class _T2> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 void swap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y) - _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && - __is_nothrow_swappable<_T2>::value) { + _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && __is_nothrow_swappable<_T2>::value) { __x.swap(__y); } diff --git a/contrib/libs/cxxsupp/libcxx/include/__memory/construct_at.h b/contrib/libs/cxxsupp/libcxx/include/__memory/construct_at.h index 789677d7a6..3b58451c50 100644 --- a/contrib/libs/cxxsupp/libcxx/include/__memory/construct_at.h +++ b/contrib/libs/cxxsupp/libcxx/include/__memory/construct_at.h @@ -41,44 +41,67 @@ constexpr _Tp* construct_at(_Tp* __location, _Args&& ...__args) { // destroy_at -#if _LIBCPP_STD_VER > 14 +// The internal functions are available regardless of the language version (with the exception of the `__destroy_at` +// taking an array). template <class _ForwardIterator> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 -void destroy(_ForwardIterator, _ForwardIterator); +void __destroy(_ForwardIterator, _ForwardIterator); -template <class _Tp, enable_if_t<!is_array_v<_Tp>, int> = 0> +template <class _Tp, typename enable_if<!is_array<_Tp>::value, int>::type = 0> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 -void destroy_at(_Tp* __loc) { +void __destroy_at(_Tp* __loc) { _LIBCPP_ASSERT(__loc, "null pointer given to destroy_at"); __loc->~_Tp(); } #if _LIBCPP_STD_VER > 17 +template <class _Tp, typename enable_if<is_array<_Tp>::value, int>::type = 0> +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 +void __destroy_at(_Tp* __loc) { + _LIBCPP_ASSERT(__loc, "null pointer given to destroy_at"); + _VSTD::__destroy(_VSTD::begin(*__loc), _VSTD::end(*__loc)); +} +#endif + +template <class _ForwardIterator> +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 +void __destroy(_ForwardIterator __first, _ForwardIterator __last) { + for (; __first != __last; ++__first) + _VSTD::__destroy_at(_VSTD::addressof(*__first)); +} + +#if _LIBCPP_STD_VER > 14 + +template <class _Tp, enable_if_t<!is_array_v<_Tp>, int> = 0> +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 +void destroy_at(_Tp* __loc) { + _VSTD::__destroy_at(__loc); +} + +#if _LIBCPP_STD_VER > 17 template <class _Tp, enable_if_t<is_array_v<_Tp>, int> = 0> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 void destroy_at(_Tp* __loc) { - _LIBCPP_ASSERT(__loc, "null pointer given to destroy_at"); - _VSTD::destroy(_VSTD::begin(*__loc), _VSTD::end(*__loc)); + _VSTD::__destroy_at(__loc); } #endif template <class _ForwardIterator> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 void destroy(_ForwardIterator __first, _ForwardIterator __last) { - for (; __first != __last; ++__first) - _VSTD::destroy_at(_VSTD::addressof(*__first)); + _VSTD::__destroy(_VSTD::move(__first), _VSTD::move(__last)); } template <class _ForwardIterator, class _Size> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator destroy_n(_ForwardIterator __first, _Size __n) { for (; __n > 0; (void)++__first, --__n) - _VSTD::destroy_at(_VSTD::addressof(*__first)); + _VSTD::__destroy_at(_VSTD::addressof(*__first)); return __first; } -#endif +#endif // _LIBCPP_STD_VER > 14 _LIBCPP_END_NAMESPACE_STD diff --git a/contrib/libs/cxxsupp/libcxx/include/__memory/ranges_uninitialized_algorithms.h b/contrib/libs/cxxsupp/libcxx/include/__memory/ranges_uninitialized_algorithms.h new file mode 100644 index 0000000000..6ec803806c --- /dev/null +++ b/contrib/libs/cxxsupp/libcxx/include/__memory/ranges_uninitialized_algorithms.h @@ -0,0 +1,212 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___MEMORY_RANGES_UNINITIALIZED_ALGORITHMS_H +#define _LIBCPP___MEMORY_RANGES_UNINITIALIZED_ALGORITHMS_H + +#include <__concepts/constructible.h> +#include <__config> +#include <__function_like.h> +#include <__iterator/incrementable_traits.h> +#include <__iterator/iterator_traits.h> +#include <__iterator/readable_traits.h> +#include <__memory/concepts.h> +#include <__memory/uninitialized_algorithms.h> +#include <__ranges/access.h> +#include <__ranges/concepts.h> +#include <__ranges/dangling.h> +#include <__utility/move.h> +#include <type_traits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if !defined(_LIBCPP_HAS_NO_RANGES) +namespace ranges { + +// uninitialized_default_construct + +namespace __uninitialized_default_construct { + +struct __fn final : private __function_like { + + constexpr explicit __fn(__tag __x) noexcept : __function_like(__x) {} + + template <__nothrow_forward_iterator _ForwardIterator, + __nothrow_sentinel_for<_ForwardIterator> _Sentinel> + requires default_initializable<iter_value_t<_ForwardIterator>> + _ForwardIterator operator()(_ForwardIterator __first, _Sentinel __last) const { + using _ValueType = remove_reference_t<iter_reference_t<_ForwardIterator>>; + return _VSTD::__uninitialized_default_construct<_ValueType>( + _VSTD::move(__first), _VSTD::move(__last)); + } + + template <__nothrow_forward_range _ForwardRange> + requires default_initializable<range_value_t<_ForwardRange>> + borrowed_iterator_t<_ForwardRange> operator()(_ForwardRange&& __range) const { + return (*this)(ranges::begin(__range), ranges::end(__range)); + } + +}; + +} // namespace __uninitialized_default_construct + +inline namespace __cpo { +inline constexpr auto uninitialized_default_construct = + __uninitialized_default_construct::__fn(__function_like::__tag()); +} // namespace __cpo + +// uninitialized_default_construct_n + +namespace __uninitialized_default_construct_n { + +struct __fn final : private __function_like { + + constexpr explicit __fn(__tag __x) noexcept : + __function_like(__x) {} + + template <__nothrow_forward_iterator _ForwardIterator> + requires default_initializable<iter_value_t<_ForwardIterator>> + _ForwardIterator operator()(_ForwardIterator __first, + iter_difference_t<_ForwardIterator> __n) const { + using _ValueType = remove_reference_t<iter_reference_t<_ForwardIterator>>; + return _VSTD::__uninitialized_default_construct_n<_ValueType>(_VSTD::move(__first), __n); + } + +}; + +} // namespace __uninitialized_default_construct_n + +inline namespace __cpo { +inline constexpr auto uninitialized_default_construct_n = + __uninitialized_default_construct_n::__fn(__function_like::__tag()); +} // namespace __cpo + +// uninitialized_value_construct + +namespace __uninitialized_value_construct { + +struct __fn final : private __function_like { + + constexpr explicit __fn(__tag __x) noexcept : __function_like(__x) {} + + template <__nothrow_forward_iterator _ForwardIterator, + __nothrow_sentinel_for<_ForwardIterator> _Sentinel> + requires default_initializable<iter_value_t<_ForwardIterator>> + _ForwardIterator operator()(_ForwardIterator __first, _Sentinel __last) const { + using _ValueType = remove_reference_t<iter_reference_t<_ForwardIterator>>; + return _VSTD::__uninitialized_value_construct<_ValueType>( + _VSTD::move(__first), _VSTD::move(__last)); + } + + template <__nothrow_forward_range _ForwardRange> + requires default_initializable<range_value_t<_ForwardRange>> + borrowed_iterator_t<_ForwardRange> operator()(_ForwardRange&& __range) const { + return (*this)(ranges::begin(__range), ranges::end(__range)); + } + +}; + +} // namespace __uninitialized_value_construct + +inline namespace __cpo { +inline constexpr auto uninitialized_value_construct = + __uninitialized_value_construct::__fn(__function_like::__tag()); +} // namespace __cpo + +// uninitialized_value_construct_n + +namespace __uninitialized_value_construct_n { + +struct __fn final : private __function_like { + + constexpr explicit __fn(__tag __x) noexcept : __function_like(__x) {} + + template <__nothrow_forward_iterator _ForwardIterator> + requires default_initializable<iter_value_t<_ForwardIterator>> + _ForwardIterator operator()(_ForwardIterator __first, + iter_difference_t<_ForwardIterator> __n) const { + using _ValueType = remove_reference_t<iter_reference_t<_ForwardIterator>>; + return _VSTD::__uninitialized_value_construct_n<_ValueType>(_VSTD::move(__first), __n); + } + +}; + +} // namespace __uninitialized_value_construct_n + +inline namespace __cpo { +inline constexpr auto uninitialized_value_construct_n = + __uninitialized_value_construct_n::__fn(__function_like::__tag()); +} // namespace __cpo + +// uninitialized_fill + +namespace __uninitialized_fill { + +struct __fn final : private __function_like { + + constexpr explicit __fn(__tag __x) noexcept : __function_like(__x) {} + + template <__nothrow_forward_iterator _ForwardIterator, + __nothrow_sentinel_for<_ForwardIterator> _Sentinel, + class _Tp> + requires constructible_from<iter_value_t<_ForwardIterator>, const _Tp&> + _ForwardIterator operator()(_ForwardIterator __first, _Sentinel __last, const _Tp& __x) const { + using _ValueType = remove_reference_t<iter_reference_t<_ForwardIterator>>; + return _VSTD::__uninitialized_fill<_ValueType>(_VSTD::move(__first), _VSTD::move(__last), __x); + } + + template <__nothrow_forward_range _ForwardRange, class _Tp> + requires constructible_from<range_value_t<_ForwardRange>, const _Tp&> + borrowed_iterator_t<_ForwardRange> operator()(_ForwardRange&& __range, const _Tp& __x) const { + return (*this)(ranges::begin(__range), ranges::end(__range), __x); + } + +}; + +} // namespace __uninitialized_fil + +inline namespace __cpo { +inline constexpr auto uninitialized_fill = __uninitialized_fill::__fn(__function_like::__tag()); +} // namespace __cpo + +// uninitialized_fill_n + +namespace __uninitialized_fill_n { + +struct __fn final : private __function_like { + + constexpr explicit __fn(__tag __x) noexcept : __function_like(__x) {} + + template <__nothrow_forward_iterator _ForwardIterator, class _Tp> + requires constructible_from<iter_value_t<_ForwardIterator>, const _Tp&> + _ForwardIterator operator()(_ForwardIterator __first, + iter_difference_t<_ForwardIterator> __n, + const _Tp& __x) const { + using _ValueType = remove_reference_t<iter_reference_t<_ForwardIterator>>; + return _VSTD::__uninitialized_fill_n<_ValueType>(_VSTD::move(__first), __n, __x); + } + +}; + +} // namespace __uninitialized_fill_n + +inline namespace __cpo { +inline constexpr auto uninitialized_fill_n = __uninitialized_fill_n::__fn(__function_like::__tag()); +} // namespace __cpo + +} // namespace ranges +#endif // !defined(_LIBCPP_HAS_NO_RANGES) + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___MEMORY_RANGES_UNINITIALIZED_ALGORITHMS_H diff --git a/contrib/libs/cxxsupp/libcxx/include/__memory/uninitialized_algorithms.h b/contrib/libs/cxxsupp/libcxx/include/__memory/uninitialized_algorithms.h index e83d62e0db..69132633a4 100644 --- a/contrib/libs/cxxsupp/libcxx/include/__memory/uninitialized_algorithms.h +++ b/contrib/libs/cxxsupp/libcxx/include/__memory/uninitialized_algorithms.h @@ -13,6 +13,7 @@ #include <__config> #include <__memory/addressof.h> #include <__memory/construct_at.h> +#include <__memory/voidify.h> #include <iterator> #include <utility> @@ -70,130 +71,187 @@ uninitialized_copy_n(_InputIterator __f, _Size __n, _ForwardIterator __r) return __r; } -template <class _ForwardIterator, class _Tp> -void -uninitialized_fill(_ForwardIterator __f, _ForwardIterator __l, const _Tp& __x) +// uninitialized_fill + +template <class _ValueType, class _ForwardIterator, class _Sentinel, class _Tp> +inline _LIBCPP_HIDE_FROM_ABI +_ForwardIterator __uninitialized_fill(_ForwardIterator __first, _Sentinel __last, const _Tp& __x) { - typedef typename iterator_traits<_ForwardIterator>::value_type value_type; + _ForwardIterator __idx = __first; #ifndef _LIBCPP_NO_EXCEPTIONS - _ForwardIterator __s = __f; try { #endif - for (; __f != __l; ++__f) - ::new ((void*)_VSTD::addressof(*__f)) value_type(__x); + for (; __idx != __last; ++__idx) + ::new (_VSTD::__voidify(*__idx)) _ValueType(__x); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { - for (; __s != __f; ++__s) - __s->~value_type(); + _VSTD::__destroy(__first, __idx); throw; } #endif + + return __idx; } -template <class _ForwardIterator, class _Size, class _Tp> -_ForwardIterator -uninitialized_fill_n(_ForwardIterator __f, _Size __n, const _Tp& __x) +template <class _ForwardIterator, class _Tp> +inline _LIBCPP_HIDE_FROM_ABI +void uninitialized_fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __x) { - typedef typename iterator_traits<_ForwardIterator>::value_type value_type; + typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType; + (void)_VSTD::__uninitialized_fill<_ValueType>(__first, __last, __x); +} + +// uninitialized_fill_n + +template <class _ValueType, class _ForwardIterator, class _Size, class _Tp> +inline _LIBCPP_HIDE_FROM_ABI +_ForwardIterator __uninitialized_fill_n(_ForwardIterator __first, _Size __n, const _Tp& __x) +{ + _ForwardIterator __idx = __first; #ifndef _LIBCPP_NO_EXCEPTIONS - _ForwardIterator __s = __f; try { #endif - for (; __n > 0; ++__f, (void) --__n) - ::new ((void*)_VSTD::addressof(*__f)) value_type(__x); + for (; __n > 0; ++__idx, (void) --__n) + ::new (_VSTD::__voidify(*__idx)) _ValueType(__x); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { - for (; __s != __f; ++__s) - __s->~value_type(); + _VSTD::__destroy(__first, __idx); throw; } #endif - return __f; + + return __idx; +} + +template <class _ForwardIterator, class _Size, class _Tp> +inline _LIBCPP_HIDE_FROM_ABI +_ForwardIterator uninitialized_fill_n(_ForwardIterator __first, _Size __n, const _Tp& __x) +{ + typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType; + return _VSTD::__uninitialized_fill_n<_ValueType>(__first, __n, __x); } #if _LIBCPP_STD_VER > 14 -template <class _ForwardIterator> -inline _LIBCPP_INLINE_VISIBILITY -void uninitialized_default_construct(_ForwardIterator __first, _ForwardIterator __last) { - using _Vt = typename iterator_traits<_ForwardIterator>::value_type; +// uninitialized_default_construct + +template <class _ValueType, class _ForwardIterator, class _Sentinel> +inline _LIBCPP_HIDE_FROM_ABI +_ForwardIterator __uninitialized_default_construct(_ForwardIterator __first, _Sentinel __last) { auto __idx = __first; #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif for (; __idx != __last; ++__idx) - ::new ((void*)_VSTD::addressof(*__idx)) _Vt; + ::new (_VSTD::__voidify(*__idx)) _ValueType; #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { - _VSTD::destroy(__first, __idx); + _VSTD::__destroy(__first, __idx); throw; } #endif + + return __idx; } -template <class _ForwardIterator, class _Size> -inline _LIBCPP_INLINE_VISIBILITY -_ForwardIterator uninitialized_default_construct_n(_ForwardIterator __first, _Size __n) { - using _Vt = typename iterator_traits<_ForwardIterator>::value_type; +template <class _ForwardIterator> +inline _LIBCPP_HIDE_FROM_ABI +void uninitialized_default_construct(_ForwardIterator __first, _ForwardIterator __last) { + using _ValueType = typename iterator_traits<_ForwardIterator>::value_type; + (void)_VSTD::__uninitialized_default_construct<_ValueType>( + _VSTD::move(__first), _VSTD::move(__last)); +} + +// uninitialized_default_construct_n + +template <class _ValueType, class _ForwardIterator, class _Size> +inline _LIBCPP_HIDE_FROM_ABI +_ForwardIterator __uninitialized_default_construct_n(_ForwardIterator __first, _Size __n) { auto __idx = __first; #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif for (; __n > 0; ++__idx, (void) --__n) - ::new ((void*)_VSTD::addressof(*__idx)) _Vt; - return __idx; + ::new (_VSTD::__voidify(*__idx)) _ValueType; #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { - _VSTD::destroy(__first, __idx); + _VSTD::__destroy(__first, __idx); throw; } #endif + + return __idx; } +template <class _ForwardIterator, class _Size> +inline _LIBCPP_HIDE_FROM_ABI +_ForwardIterator uninitialized_default_construct_n(_ForwardIterator __first, _Size __n) { + using _ValueType = typename iterator_traits<_ForwardIterator>::value_type; + return _VSTD::__uninitialized_default_construct_n<_ValueType>(_VSTD::move(__first), __n); +} -template <class _ForwardIterator> -inline _LIBCPP_INLINE_VISIBILITY -void uninitialized_value_construct(_ForwardIterator __first, _ForwardIterator __last) { - using _Vt = typename iterator_traits<_ForwardIterator>::value_type; +// uninitialized_value_construct + +template <class _ValueType, class _ForwardIterator, class _Sentinel> +inline _LIBCPP_HIDE_FROM_ABI +_ForwardIterator __uninitialized_value_construct(_ForwardIterator __first, _Sentinel __last) { auto __idx = __first; #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif for (; __idx != __last; ++__idx) - ::new ((void*)_VSTD::addressof(*__idx)) _Vt(); + ::new (_VSTD::__voidify(*__idx)) _ValueType(); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { - _VSTD::destroy(__first, __idx); + _VSTD::__destroy(__first, __idx); throw; } #endif + + return __idx; } -template <class _ForwardIterator, class _Size> -inline _LIBCPP_INLINE_VISIBILITY -_ForwardIterator uninitialized_value_construct_n(_ForwardIterator __first, _Size __n) { - using _Vt = typename iterator_traits<_ForwardIterator>::value_type; +template <class _ForwardIterator> +inline _LIBCPP_HIDE_FROM_ABI +void uninitialized_value_construct(_ForwardIterator __first, _ForwardIterator __last) { + using _ValueType = typename iterator_traits<_ForwardIterator>::value_type; + (void)_VSTD::__uninitialized_value_construct<_ValueType>( + _VSTD::move(__first), _VSTD::move(__last)); +} + +// uninitialized_value_construct_n + +template <class _ValueType, class _ForwardIterator, class _Size> +inline _LIBCPP_HIDE_FROM_ABI +_ForwardIterator __uninitialized_value_construct_n(_ForwardIterator __first, _Size __n) { auto __idx = __first; #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif for (; __n > 0; ++__idx, (void) --__n) - ::new ((void*)_VSTD::addressof(*__idx)) _Vt(); - return __idx; + ::new (_VSTD::__voidify(*__idx)) _ValueType(); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { - _VSTD::destroy(__first, __idx); + _VSTD::__destroy(__first, __idx); throw; } #endif + + return __idx; } +template <class _ForwardIterator, class _Size> +inline _LIBCPP_HIDE_FROM_ABI +_ForwardIterator uninitialized_value_construct_n(_ForwardIterator __first, _Size __n) { + using _ValueType = typename iterator_traits<_ForwardIterator>::value_type; + return __uninitialized_value_construct_n<_ValueType>(_VSTD::move(__first), __n); +} template <class _InputIt, class _ForwardIt> inline _LIBCPP_INLINE_VISIBILITY diff --git a/contrib/libs/cxxsupp/libcxx/include/__memory/voidify.h b/contrib/libs/cxxsupp/libcxx/include/__memory/voidify.h new file mode 100644 index 0000000000..3a65c0e83f --- /dev/null +++ b/contrib/libs/cxxsupp/libcxx/include/__memory/voidify.h @@ -0,0 +1,30 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___MEMORY_VOIDIFY_H +#define _LIBCPP___MEMORY_VOIDIFY_H + +#include <__config> +#include <__memory/addressof.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +template <typename _Tp> +_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 void* __voidify(_Tp& __from) { + // Cast away cv-qualifiers to allow modifying elements of a range through const iterators. + return const_cast<void*>(static_cast<const volatile void*>(_VSTD::addressof(__from))); +} + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___MEMORY_VOIDIFY_H diff --git a/contrib/libs/cxxsupp/libcxx/include/__random/random_device.h b/contrib/libs/cxxsupp/libcxx/include/__random/random_device.h index 6a6b0cc306..835f726fdb 100644 --- a/contrib/libs/cxxsupp/libcxx/include/__random/random_device.h +++ b/contrib/libs/cxxsupp/libcxx/include/__random/random_device.h @@ -27,7 +27,7 @@ class _LIBCPP_TYPE_VIS random_device { #ifdef _LIBCPP_USING_DEV_RANDOM int __f_; -#endif // defined(_LIBCPP_USING_DEV_RANDOM) +#endif public: // types typedef unsigned result_type; diff --git a/contrib/libs/cxxsupp/libcxx/include/__string b/contrib/libs/cxxsupp/libcxx/include/__string index 6b7d50b1ed..c07c165221 100644 --- a/contrib/libs/cxxsupp/libcxx/include/__string +++ b/contrib/libs/cxxsupp/libcxx/include/__string @@ -297,31 +297,34 @@ char_traits<_CharT>::assign(char_type* __s, size_t __n, char_type __a) template <class _CharT> static inline _LIBCPP_CONSTEXPR_AFTER_CXX17 -_CharT* __move_constexpr(_CharT* __s1, const _CharT* __s2, size_t __n) _NOEXCEPT +_CharT* __copy_constexpr(_CharT* __dest, const _CharT* __source, size_t __n) _NOEXCEPT { - if (__n == 0) return __s1; - if (__s1 < __s2) { - _VSTD::copy(__s2, __s2 + __n, __s1); - } else if (__s2 < __s1) { - _VSTD::copy_backward(__s2, __s2 + __n, __s1 + __n); - } - return __s1; + _LIBCPP_ASSERT(__libcpp_is_constant_evaluated(), "__copy_constexpr() should always be constant evaluated"); + _VSTD::copy_n(__source, __n, __dest); + return __dest; } template <class _CharT> static inline _LIBCPP_CONSTEXPR_AFTER_CXX17 -_CharT* __copy_constexpr(_CharT* __s1, const _CharT* __s2, size_t __n) _NOEXCEPT +_CharT* __move_constexpr(_CharT* __dest, const _CharT* __source, size_t __n) _NOEXCEPT { - _VSTD::copy_n(__s2, __n, __s1); - return __s1; + _LIBCPP_ASSERT(__libcpp_is_constant_evaluated(), "__move_constexpr() should always be constant evaluated"); + if (__n == 0) + return __dest; + _CharT* __allocation = new _CharT[__n]; + _VSTD::__copy_constexpr(__allocation, __source, __n); + _VSTD::__copy_constexpr(__dest, static_cast<const _CharT*>(__allocation), __n); + delete[] __allocation; + return __dest; } template <class _CharT> static inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _CharT* __assign_constexpr(_CharT* __s, size_t __n, _CharT __a) _NOEXCEPT { - _VSTD::fill_n(__s, __n, __a); - return __s; + _LIBCPP_ASSERT(__libcpp_is_constant_evaluated(), "__assign_constexpr() should always be constant evaluated"); + _VSTD::fill_n(__s, __n, __a); + return __s; } // char_traits<char> @@ -344,18 +347,20 @@ struct _LIBCPP_TEMPLATE_VIS char_traits<char> static _LIBCPP_CONSTEXPR_AFTER_CXX14 int compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT; -#ifdef _LIBCPP_COMPILER_MSVC - static inline size_t _LIBCPP_CONSTEXPR_AFTER_CXX14 length(const char_type* __s) _NOEXCEPT - { - size_t __len = 0; - for (; !eq(*__s, char_type(0)); ++__s) - ++__len; - return __len; - } -#else - static inline size_t _LIBCPP_CONSTEXPR_AFTER_CXX14 - length(const char_type* __s) _NOEXCEPT {return __builtin_strlen(__s);} + static inline size_t _LIBCPP_CONSTEXPR_AFTER_CXX14 length(const char_type* __s) _NOEXCEPT { + // GCC currently does not support __builtin_strlen during constant evaluation. + // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70816 +#ifdef _LIBCPP_COMPILER_GCC || _LIBCPP_COMPILER_MSVC + if (__libcpp_is_constant_evaluated()) { + size_t __i = 0; + for (; __s[__i] != char_type('\0'); ++__i) + ; + return __i; + } #endif + return __builtin_strlen(__s); + } + static _LIBCPP_CONSTEXPR_AFTER_CXX14 const char_type* find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT; static inline _LIBCPP_CONSTEXPR_AFTER_CXX17 diff --git a/contrib/libs/cxxsupp/libcxx/include/__threading_support b/contrib/libs/cxxsupp/libcxx/include/__threading_support index 54d99e36b3..89ea4a9169 100644 --- a/contrib/libs/cxxsupp/libcxx/include/__threading_support +++ b/contrib/libs/cxxsupp/libcxx/include/__threading_support @@ -276,7 +276,8 @@ struct __libcpp_timed_backoff_policy { namespace __thread_detail { -inline __libcpp_timespec_t __convert_to_timespec(const chrono::nanoseconds& __ns) +_LIBCPP_HIDE_FROM_ABI inline +__libcpp_timespec_t __convert_to_timespec(const chrono::nanoseconds& __ns) { using namespace chrono; seconds __s = duration_cast<seconds>(__ns); @@ -302,6 +303,7 @@ inline __libcpp_timespec_t __convert_to_timespec(const chrono::nanoseconds& __ns #if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) +_LIBCPP_HIDE_FROM_ABI inline int __libcpp_recursive_mutex_init(__libcpp_recursive_mutex_t *__m) { pthread_mutexattr_t attr; @@ -326,74 +328,88 @@ int __libcpp_recursive_mutex_init(__libcpp_recursive_mutex_t *__m) return 0; } +_LIBCPP_HIDE_FROM_ABI inline int __libcpp_recursive_mutex_lock(__libcpp_recursive_mutex_t *__m) { return pthread_mutex_lock(__m); } +_LIBCPP_HIDE_FROM_ABI inline bool __libcpp_recursive_mutex_trylock(__libcpp_recursive_mutex_t *__m) { return pthread_mutex_trylock(__m) == 0; } +_LIBCPP_HIDE_FROM_ABI inline int __libcpp_recursive_mutex_unlock(__libcpp_recursive_mutex_t *__m) { return pthread_mutex_unlock(__m); } +_LIBCPP_HIDE_FROM_ABI inline int __libcpp_recursive_mutex_destroy(__libcpp_recursive_mutex_t *__m) { return pthread_mutex_destroy(__m); } +_LIBCPP_HIDE_FROM_ABI inline int __libcpp_mutex_lock(__libcpp_mutex_t *__m) { return pthread_mutex_lock(__m); } +_LIBCPP_HIDE_FROM_ABI inline bool __libcpp_mutex_trylock(__libcpp_mutex_t *__m) { return pthread_mutex_trylock(__m) == 0; } +_LIBCPP_HIDE_FROM_ABI inline int __libcpp_mutex_unlock(__libcpp_mutex_t *__m) { return pthread_mutex_unlock(__m); } +_LIBCPP_HIDE_FROM_ABI inline int __libcpp_mutex_destroy(__libcpp_mutex_t *__m) { return pthread_mutex_destroy(__m); } // Condition Variable +_LIBCPP_HIDE_FROM_ABI inline int __libcpp_condvar_signal(__libcpp_condvar_t *__cv) { return pthread_cond_signal(__cv); } +_LIBCPP_HIDE_FROM_ABI inline int __libcpp_condvar_broadcast(__libcpp_condvar_t *__cv) { return pthread_cond_broadcast(__cv); } +_LIBCPP_HIDE_FROM_ABI inline int __libcpp_condvar_wait(__libcpp_condvar_t *__cv, __libcpp_mutex_t *__m) { return pthread_cond_wait(__cv, __m); } +_LIBCPP_HIDE_FROM_ABI inline int __libcpp_condvar_timedwait(__libcpp_condvar_t *__cv, __libcpp_mutex_t *__m, __libcpp_timespec_t *__ts) { return pthread_cond_timedwait(__cv, __m, __ts); } +_LIBCPP_HIDE_FROM_ABI inline int __libcpp_condvar_destroy(__libcpp_condvar_t *__cv) { return pthread_cond_destroy(__cv); } // Execute once +_LIBCPP_HIDE_FROM_ABI inline int __libcpp_execute_once(__libcpp_exec_once_flag *flag, void (*init_routine)()) { return pthread_once(flag, init_routine); @@ -401,34 +417,40 @@ int __libcpp_execute_once(__libcpp_exec_once_flag *flag, // Thread id // Returns non-zero if the thread ids are equal, otherwise 0 +_LIBCPP_HIDE_FROM_ABI inline bool __libcpp_thread_id_equal(__libcpp_thread_id t1, __libcpp_thread_id t2) { return t1 == t2; } // Returns non-zero if t1 < t2, otherwise 0 +_LIBCPP_HIDE_FROM_ABI inline bool __libcpp_thread_id_less(__libcpp_thread_id t1, __libcpp_thread_id t2) { return t1 < t2; } // Thread +_LIBCPP_HIDE_FROM_ABI inline bool __libcpp_thread_isnull(const __libcpp_thread_t *__t) { return __libcpp_thread_get_id(__t) == 0; } +_LIBCPP_HIDE_FROM_ABI inline int __libcpp_thread_create(__libcpp_thread_t *__t, void *(*__func)(void *), void *__arg) { return pthread_create(__t, nullptr, __func, __arg); } +_LIBCPP_HIDE_FROM_ABI inline __libcpp_thread_id __libcpp_thread_get_current_id() { const __libcpp_thread_t thread = pthread_self(); return __libcpp_thread_get_id(&thread); } +_LIBCPP_HIDE_FROM_ABI inline __libcpp_thread_id __libcpp_thread_get_id(const __libcpp_thread_t *__t) { #if defined(__MVS__) @@ -438,21 +460,25 @@ __libcpp_thread_id __libcpp_thread_get_id(const __libcpp_thread_t *__t) #endif } +_LIBCPP_HIDE_FROM_ABI inline int __libcpp_thread_join(__libcpp_thread_t *__t) { return pthread_join(*__t, nullptr); } +_LIBCPP_HIDE_FROM_ABI inline int __libcpp_thread_detach(__libcpp_thread_t *__t) { return pthread_detach(*__t); } +_LIBCPP_HIDE_FROM_ABI inline void __libcpp_thread_yield() { sched_yield(); } +_LIBCPP_HIDE_FROM_ABI inline void __libcpp_thread_sleep_for(const chrono::nanoseconds& __ns) { __libcpp_timespec_t __ts = __thread_detail::__convert_to_timespec(__ns); @@ -460,16 +486,19 @@ void __libcpp_thread_sleep_for(const chrono::nanoseconds& __ns) } // Thread local storage +_LIBCPP_HIDE_FROM_ABI inline int __libcpp_tls_create(__libcpp_tls_key *__key, void (*__at_exit)(void *)) { return pthread_key_create(__key, __at_exit); } +_LIBCPP_HIDE_FROM_ABI inline void *__libcpp_tls_get(__libcpp_tls_key __key) { return pthread_getspecific(__key); } +_LIBCPP_HIDE_FROM_ABI inline int __libcpp_tls_set(__libcpp_tls_key __key, void *__p) { return pthread_setspecific(__key, __p); @@ -477,47 +506,56 @@ int __libcpp_tls_set(__libcpp_tls_key __key, void *__p) #elif defined(_LIBCPP_HAS_THREAD_API_C11) +_LIBCPP_HIDE_FROM_ABI inline int __libcpp_recursive_mutex_init(__libcpp_recursive_mutex_t *__m) { return mtx_init(__m, mtx_plain | mtx_recursive) == thrd_success ? 0 : EINVAL; } +_LIBCPP_HIDE_FROM_ABI inline int __libcpp_recursive_mutex_lock(__libcpp_recursive_mutex_t *__m) { return mtx_lock(__m) == thrd_success ? 0 : EINVAL; } +_LIBCPP_HIDE_FROM_ABI inline bool __libcpp_recursive_mutex_trylock(__libcpp_recursive_mutex_t *__m) { return mtx_trylock(__m) == thrd_success; } +_LIBCPP_HIDE_FROM_ABI inline int __libcpp_recursive_mutex_unlock(__libcpp_recursive_mutex_t *__m) { return mtx_unlock(__m) == thrd_success ? 0 : EINVAL; } +_LIBCPP_HIDE_FROM_ABI inline int __libcpp_recursive_mutex_destroy(__libcpp_recursive_mutex_t *__m) { mtx_destroy(__m); return 0; } +_LIBCPP_HIDE_FROM_ABI inline int __libcpp_mutex_lock(__libcpp_mutex_t *__m) { return mtx_lock(__m) == thrd_success ? 0 : EINVAL; } +_LIBCPP_HIDE_FROM_ABI inline bool __libcpp_mutex_trylock(__libcpp_mutex_t *__m) { return mtx_trylock(__m) == thrd_success; } +_LIBCPP_HIDE_FROM_ABI inline int __libcpp_mutex_unlock(__libcpp_mutex_t *__m) { return mtx_unlock(__m) == thrd_success ? 0 : EINVAL; } +_LIBCPP_HIDE_FROM_ABI inline int __libcpp_mutex_destroy(__libcpp_mutex_t *__m) { mtx_destroy(__m); @@ -525,21 +563,25 @@ int __libcpp_mutex_destroy(__libcpp_mutex_t *__m) } // Condition Variable +_LIBCPP_HIDE_FROM_ABI inline int __libcpp_condvar_signal(__libcpp_condvar_t *__cv) { return cnd_signal(__cv) == thrd_success ? 0 : EINVAL; } +_LIBCPP_HIDE_FROM_ABI inline int __libcpp_condvar_broadcast(__libcpp_condvar_t *__cv) { return cnd_broadcast(__cv) == thrd_success ? 0 : EINVAL; } +_LIBCPP_HIDE_FROM_ABI inline int __libcpp_condvar_wait(__libcpp_condvar_t *__cv, __libcpp_mutex_t *__m) { return cnd_wait(__cv, __m) == thrd_success ? 0 : EINVAL; } +_LIBCPP_HIDE_FROM_ABI inline int __libcpp_condvar_timedwait(__libcpp_condvar_t *__cv, __libcpp_mutex_t *__m, timespec *__ts) { @@ -547,6 +589,7 @@ int __libcpp_condvar_timedwait(__libcpp_condvar_t *__cv, __libcpp_mutex_t *__m, return __ec == thrd_timedout ? ETIMEDOUT : __ec; } +_LIBCPP_HIDE_FROM_ABI inline int __libcpp_condvar_destroy(__libcpp_condvar_t *__cv) { cnd_destroy(__cv); @@ -554,6 +597,7 @@ int __libcpp_condvar_destroy(__libcpp_condvar_t *__cv) } // Execute once +_LIBCPP_HIDE_FROM_ABI inline int __libcpp_execute_once(__libcpp_exec_once_flag *flag, void (*init_routine)(void)) { ::call_once(flag, init_routine); @@ -562,22 +606,26 @@ int __libcpp_execute_once(__libcpp_exec_once_flag *flag, // Thread id // Returns non-zero if the thread ids are equal, otherwise 0 +_LIBCPP_HIDE_FROM_ABI inline bool __libcpp_thread_id_equal(__libcpp_thread_id t1, __libcpp_thread_id t2) { return thrd_equal(t1, t2) != 0; } // Returns non-zero if t1 < t2, otherwise 0 +_LIBCPP_HIDE_FROM_ABI inline bool __libcpp_thread_id_less(__libcpp_thread_id t1, __libcpp_thread_id t2) { return t1 < t2; } // Thread +_LIBCPP_HIDE_FROM_ABI inline bool __libcpp_thread_isnull(const __libcpp_thread_t *__t) { return __libcpp_thread_get_id(__t) == 0; } +_LIBCPP_HIDE_FROM_ABI inline int __libcpp_thread_create(__libcpp_thread_t *__t, void *(*__func)(void *), void *__arg) { @@ -585,31 +633,37 @@ int __libcpp_thread_create(__libcpp_thread_t *__t, void *(*__func)(void *), return __ec == thrd_nomem ? ENOMEM : __ec; } +_LIBCPP_HIDE_FROM_ABI inline __libcpp_thread_id __libcpp_thread_get_current_id() { return thrd_current(); } +_LIBCPP_HIDE_FROM_ABI inline __libcpp_thread_id __libcpp_thread_get_id(const __libcpp_thread_t *__t) { return *__t; } +_LIBCPP_HIDE_FROM_ABI inline int __libcpp_thread_join(__libcpp_thread_t *__t) { return thrd_join(*__t, nullptr) == thrd_success ? 0 : EINVAL; } +_LIBCPP_HIDE_FROM_ABI inline int __libcpp_thread_detach(__libcpp_thread_t *__t) { return thrd_detach(*__t) == thrd_success ? 0 : EINVAL; } +_LIBCPP_HIDE_FROM_ABI inline void __libcpp_thread_yield() { thrd_yield(); } +_LIBCPP_HIDE_FROM_ABI inline void __libcpp_thread_sleep_for(const chrono::nanoseconds& __ns) { __libcpp_timespec_t __ts = __thread_detail::__convert_to_timespec(__ns); @@ -617,16 +671,19 @@ void __libcpp_thread_sleep_for(const chrono::nanoseconds& __ns) } // Thread local storage +_LIBCPP_HIDE_FROM_ABI inline int __libcpp_tls_create(__libcpp_tls_key *__key, void (*__at_exit)(void *)) { return tss_create(__key, __at_exit) == thrd_success ? 0 : EINVAL; } +_LIBCPP_HIDE_FROM_ABI inline void *__libcpp_tls_get(__libcpp_tls_key __key) { return tss_get(__key); } +_LIBCPP_HIDE_FROM_ABI inline int __libcpp_tls_set(__libcpp_tls_key __key, void *__p) { return tss_set(__key, __p) == thrd_success ? 0 : EINVAL; diff --git a/contrib/libs/cxxsupp/libcxx/include/__tuple b/contrib/libs/cxxsupp/libcxx/include/__tuple index 08f4dd5efa..0dd5cf1fe3 100644 --- a/contrib/libs/cxxsupp/libcxx/include/__tuple +++ b/contrib/libs/cxxsupp/libcxx/include/__tuple @@ -466,7 +466,7 @@ template <bool ..._Preds> struct __all_dummy; template <bool ..._Pred> -using __all = _IsSame<__all_dummy<_Pred...>, __all_dummy<(_Pred | true)...>>; +struct __all : _IsSame<__all_dummy<_Pred...>, __all_dummy<(_Pred | true)...>>{}; struct __tuple_sfinae_base { template <template <class, class...> class _Trait, diff --git a/contrib/libs/cxxsupp/libcxx/include/__utility/decay_copy.h b/contrib/libs/cxxsupp/libcxx/include/__utility/decay_copy.h index 5c9716a892..32238e117f 100644 --- a/contrib/libs/cxxsupp/libcxx/include/__utility/decay_copy.h +++ b/contrib/libs/cxxsupp/libcxx/include/__utility/decay_copy.h @@ -24,7 +24,7 @@ template <class _Tp> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR typename decay<_Tp>::type __decay_copy(_Tp&& __t) #if _LIBCPP_STD_VER > 17 - noexcept(is_nothrow_convertible_v<_Tp, remove_reference_t<_Tp>>) + noexcept(is_nothrow_convertible_v<_Tp, decay_t<_Tp>>) #endif { return _VSTD::forward<_Tp>(__t); diff --git a/contrib/libs/cxxsupp/libcxx/include/__utility/transaction.h b/contrib/libs/cxxsupp/libcxx/include/__utility/transaction.h new file mode 100644 index 0000000000..1fbadf4871 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxx/include/__utility/transaction.h @@ -0,0 +1,94 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___UTILITY_TRANSACTION_H +#define _LIBCPP___UTILITY_TRANSACTION_H + +#include <__config> +#include <__utility/exchange.h> +#include <__utility/move.h> +#include <type_traits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +// __transaction is a helper class for writing code with the strong exception guarantee. +// +// When writing code that can throw an exception, one can store rollback instructions in a +// transaction so that if an exception is thrown at any point during the lifetime of the +// transaction, it will be rolled back automatically. When the transaction is done, one +// must mark it as being complete so it isn't rolled back when the transaction is destroyed. +// +// Transactions are not default constructible, they can't be copied or assigned to, but +// they can be moved around for convenience. +// +// __transaction can help greatly simplify code that would normally be cluttered by +// `#if _LIBCPP_NO_EXCEPTIONS`. For example: +// +// template <class Iterator, class Size, class OutputIterator> +// Iterator uninitialized_copy_n(Iterator iter, Size n, OutputIterator out) { +// typedef typename iterator_traits<Iterator>::value_type value_type; +// __transaction transaction([start=out, &out] { +// std::destroy(start, out); +// }); +// +// for (; n > 0; ++iter, ++out, --n) { +// ::new ((void*)std::addressof(*out)) value_type(*iter); +// } +// transaction.__complete(); +// return out; +// } +// +template <class _Rollback> +struct __transaction { + __transaction() = delete; + + _LIBCPP_HIDE_FROM_ABI + _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit __transaction(_Rollback __rollback) + : __rollback_(_VSTD::move(__rollback)) + , __completed_(false) + { } + + _LIBCPP_HIDE_FROM_ABI + _LIBCPP_CONSTEXPR_AFTER_CXX17 __transaction(__transaction&& __other) + _NOEXCEPT_(is_nothrow_move_constructible<_Rollback>::value) + : __rollback_(_VSTD::move(__other.__rollback_)) + , __completed_(__other.__completed_) + { + __other.__completed_ = true; + } + + __transaction(__transaction const&) = delete; + __transaction& operator=(__transaction const&) = delete; + __transaction& operator=(__transaction&&) = delete; + + _LIBCPP_HIDE_FROM_ABI + _LIBCPP_CONSTEXPR_AFTER_CXX17 void __complete() _NOEXCEPT { + __completed_ = true; + } + + _LIBCPP_HIDE_FROM_ABI +#if !defined(_LIBCPP_COMPILER_MSVC) + _LIBCPP_CONSTEXPR_AFTER_CXX17 +#endif + ~__transaction() { + if (!__completed_) + __rollback_(); + } + +private: + _Rollback __rollback_; + bool __completed_; +}; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___UTILITY_TRANSACTION_H diff --git a/contrib/libs/cxxsupp/libcxx/include/atomic b/contrib/libs/cxxsupp/libcxx/include/atomic index da3bfb03aa..a2230de042 100644 --- a/contrib/libs/cxxsupp/libcxx/include/atomic +++ b/contrib/libs/cxxsupp/libcxx/include/atomic @@ -2734,6 +2734,13 @@ typedef atomic<__libcpp_unsigned_lock_free> atomic_unsigned_lock_free; #define ATOMIC_FLAG_INIT {false} #define ATOMIC_VAR_INIT(__v) {__v} +#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS) +# if defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER >= 1400 +# pragma clang deprecated(ATOMIC_FLAG_INIT) +# pragma clang deprecated(ATOMIC_VAR_INIT) +# endif +#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS) + _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP_ATOMIC diff --git a/contrib/libs/cxxsupp/libcxx/include/bit b/contrib/libs/cxxsupp/libcxx/include/bit index 0aab83e7a6..57a13768c4 100644 --- a/contrib/libs/cxxsupp/libcxx/include/bit +++ b/contrib/libs/cxxsupp/libcxx/include/bit @@ -308,7 +308,7 @@ bit_ceil(_Tp __t) noexcept { if (__t < 2) return 1; const unsigned __n = numeric_limits<_Tp>::digits - countl_zero((_Tp)(__t - 1u)); - _LIBCPP_DEBUG_ASSERT(__libcpp_is_constant_evaluated() || __n != numeric_limits<_Tp>::digits, "Bad input to bit_ceil"); + _LIBCPP_ASSERT(__n != numeric_limits<_Tp>::digits, "Bad input to bit_ceil"); if constexpr (sizeof(_Tp) >= sizeof(unsigned)) return _Tp{1} << __n; diff --git a/contrib/libs/cxxsupp/libcxx/include/memory b/contrib/libs/cxxsupp/libcxx/include/memory index 9b3e294467..bbf093df9e 100644 --- a/contrib/libs/cxxsupp/libcxx/include/memory +++ b/contrib/libs/cxxsupp/libcxx/include/memory @@ -188,10 +188,22 @@ uninitialized_copy_n(InputIterator first, Size n, ForwardIterator result); template <class ForwardIterator, class T> void uninitialized_fill(ForwardIterator first, ForwardIterator last, const T& x); +template <nothrow-forward-iterator ForwardIterator, nothrow-sentinel-for<ForwardIterator> Sentinel, class T> + requires constructible_from<iter_value_t<ForwardIterator>, const T&> +ForwardIterator ranges::uninitialized_fill(ForwardIterator first, Sentinel last, const T& x); // since C++20 + +template <nothrow-forward-range ForwardRange, class T> + requires constructible_from<range_value_t<ForwardRange>, const T&> +borrowed_iterator_t<ForwardRange> ranges::uninitialized_fill(ForwardRange&& range, const T& x); // since C++20 + template <class ForwardIterator, class Size, class T> ForwardIterator uninitialized_fill_n(ForwardIterator first, Size n, const T& x); +template <nothrow-forward-iterator ForwardIterator, class T> + requires constructible_from<iter_value_t<ForwardIterator>, const T&> +ForwardIterator ranges::uninitialized_fill_n(ForwardIterator first, iter_difference_t<ForwardIterator> n); // since C++20 + template <class T, class ...Args> constexpr T* construct_at(T* location, Args&& ...args); // since C++20 @@ -213,15 +225,39 @@ template <class InputIterator, class Size, class ForwardIterator> template <class ForwardIterator> void uninitialized_value_construct(ForwardIterator first, ForwardIterator last); +template <nothrow-forward-iterator ForwardIterator, nothrow-sentinel-for<ForwardIterator> Sentinel> + requires default_initializable<iter_value_t<ForwardIterator>> + ForwardIterator ranges::uninitialized_value_construct(ForwardIterator first, Sentinel last); // since C++20 + +template <nothrow-forward-range ForwardRange> + requires default_initializable<range_value_t<ForwardRange>> + borrowed_iterator_t<ForwardRange> ranges::uninitialized_value_construct(ForwardRange&& r); // since C++20 + template <class ForwardIterator, class Size> ForwardIterator uninitialized_value_construct_n(ForwardIterator first, Size n); +template <nothrow-forward-iterator ForwardIterator> + requires default_initializable<iter_value_t<ForwardIterator>> + ForwardIterator ranges::uninitialized_value_construct_n(ForwardIterator first, iter_difference_t<ForwardIterator> n); // since C++20 + template <class ForwardIterator> void uninitialized_default_construct(ForwardIterator first, ForwardIterator last); +template <nothrow-forward-iterator ForwardIterator, nothrow-sentinel-for<ForwardIterator> Sentinel> + requires default_initializable<iter_value_t<ForwardIterator>> + ForwardIterator ranges::uninitialized_default_construct(ForwardIterator first, Sentinel last); // since C++20 + +template <nothrow-forward-range ForwardRange> + requires default_initializable<range_value_t<ForwardRange>> + borrowed_iterator_t<ForwardRange> ranges::uninitialized_default_construct(ForwardRange&& r); // since C++20 + template <class ForwardIterator, class Size> ForwardIterator uninitialized_default_construct_n(ForwardIterator first, Size n); +template <nothrow-forward-iterator ForwardIterator> + requires default_initializable<iter_value_t<ForwardIterator>> + ForwardIterator ranges::uninitialized_default_construct_n(ForwardIterator first, iter_difference_t<ForwardIterator> n); // since C++20 + template <class Y> struct auto_ptr_ref {}; // deprecated in C++11, removed in C++17 template<class X> @@ -672,6 +708,7 @@ void* align(size_t alignment, size_t size, void*& ptr, size_t& space); #include <__memory/concepts.h> #include <__memory/construct_at.h> #include <__memory/pointer_traits.h> +#include <__memory/ranges_uninitialized_algorithms.h> #include <__memory/raw_storage_iterator.h> #include <__memory/shared_ptr.h> #include <__memory/temporary_buffer.h> @@ -833,9 +870,9 @@ _LIBCPP_FUNC_VIS void* align(size_t __align, size_t __sz, void*& __ptr, size_t& // --- Helper for container swap -- template <typename _Alloc> -_LIBCPP_INLINE_VISIBILITY +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 void __swap_allocator(_Alloc & __a1, _Alloc & __a2, true_type) -#if _LIBCPP_STD_VER >= 14 +#if _LIBCPP_STD_VER > 11 _NOEXCEPT #else _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value) @@ -846,13 +883,13 @@ void __swap_allocator(_Alloc & __a1, _Alloc & __a2, true_type) } template <typename _Alloc> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 void __swap_allocator(_Alloc &, _Alloc &, false_type) _NOEXCEPT {} template <typename _Alloc> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 void __swap_allocator(_Alloc & __a1, _Alloc & __a2) -#if _LIBCPP_STD_VER >= 14 +#if _LIBCPP_STD_VER > 11 _NOEXCEPT #else _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value) diff --git a/contrib/libs/cxxsupp/libcxx/include/module.modulemap b/contrib/libs/cxxsupp/libcxx/include/module.modulemap index ae1d2aeba9..fa4170ba1e 100644 --- a/contrib/libs/cxxsupp/libcxx/include/module.modulemap +++ b/contrib/libs/cxxsupp/libcxx/include/module.modulemap @@ -630,22 +630,27 @@ module std [system] { export * module __memory { - module addressof { private header "__memory/addressof.h" } - module allocation_guard { private header "__memory/allocation_guard.h" } - module allocator { private header "__memory/allocator.h" } - module allocator_arg_t { private header "__memory/allocator_arg_t.h" } - module allocator_traits { private header "__memory/allocator_traits.h" } - module auto_ptr { private header "__memory/auto_ptr.h" } - module compressed_pair { private header "__memory/compressed_pair.h" } - module concepts { private header "__memory/concepts.h" } - module construct_at { private header "__memory/construct_at.h" } - module pointer_traits { private header "__memory/pointer_traits.h" } - module raw_storage_iterator { private header "__memory/raw_storage_iterator.h" } - module shared_ptr { private header "__memory/shared_ptr.h" } - module temporary_buffer { private header "__memory/temporary_buffer.h" } - module uninitialized_algorithms { private header "__memory/uninitialized_algorithms.h" } - module unique_ptr { private header "__memory/unique_ptr.h" } - module uses_allocator { private header "__memory/uses_allocator.h" } + module addressof { private header "__memory/addressof.h" } + module allocation_guard { private header "__memory/allocation_guard.h" } + module allocator { private header "__memory/allocator.h" } + module allocator_arg_t { private header "__memory/allocator_arg_t.h" } + module allocator_traits { private header "__memory/allocator_traits.h" } + module auto_ptr { private header "__memory/auto_ptr.h" } + module compressed_pair { private header "__memory/compressed_pair.h" } + module concepts { private header "__memory/concepts.h" } + module construct_at { private header "__memory/construct_at.h" } + module pointer_traits { private header "__memory/pointer_traits.h" } + module ranges_uninitialized_algorithms { + private header "__memory/ranges_uninitialized_algorithms.h" + export __function_like + } + module raw_storage_iterator { private header "__memory/raw_storage_iterator.h" } + module shared_ptr { private header "__memory/shared_ptr.h" } + module temporary_buffer { private header "__memory/temporary_buffer.h" } + module uninitialized_algorithms { private header "__memory/uninitialized_algorithms.h" } + module unique_ptr { private header "__memory/unique_ptr.h" } + module uses_allocator { private header "__memory/uses_allocator.h" } + module voidify { private header "__memory/voidify.h" } } } module mutex { @@ -755,7 +760,10 @@ module std [system] { module common_view { private header "__ranges/common_view.h" } module concepts { private header "__ranges/concepts.h" } module copyable_box { private header "__ranges/copyable_box.h" } - module counted { private header "__ranges/counted.h" } + module counted { + private header "__ranges/counted.h" + export span + } module dangling { private header "__ranges/dangling.h" } module data { private header "__ranges/data.h" } module drop_view { private header "__ranges/drop_view.h" } @@ -908,6 +916,7 @@ module std [system] { module rel_ops { private header "__utility/rel_ops.h" } module swap { private header "__utility/swap.h" } module to_underlying { private header "__utility/to_underlying.h" } + module transaction { private header "__utility/transaction.h" } } } module valarray { diff --git a/contrib/libs/cxxsupp/libcxx/include/optional b/contrib/libs/cxxsupp/libcxx/include/optional index 1d16767dcf..805e2e6d04 100644 --- a/contrib/libs/cxxsupp/libcxx/include/optional +++ b/contrib/libs/cxxsupp/libcxx/include/optional @@ -132,6 +132,18 @@ namespace std { template <class U> constexpr T value_or(U &&) const &; template <class U> constexpr T value_or(U &&) &&; + // [optional.monadic], monadic operations + template<class F> constexpr auto and_then(F&& f) &; // since C++23 + template<class F> constexpr auto and_then(F&& f) &&; // since C++23 + template<class F> constexpr auto and_then(F&& f) const&; // since C++23 + template<class F> constexpr auto and_then(F&& f) const&&; // since C++23 + template<class F> constexpr auto transform(F&& f) &; // since C++23 + template<class F> constexpr auto transform(F&& f) &&; // since C++23 + template<class F> constexpr auto transform(F&& f) const&; // since C++23 + template<class F> constexpr auto transform(F&& f) const&&; // since C++23 + template<class F> constexpr optional or_else(F&& f) &&; // since C++23 + template<class F> constexpr optional or_else(F&& f) const&; // since C++23 + // 23.6.3.6, modifiers void reset() noexcept; // constexpr in C++20 @@ -147,6 +159,7 @@ template<class T> */ #include <__availability> +#include <__concepts/invocable.h> #include <__config> #include <__debug> #include <__functional_base> @@ -200,6 +213,8 @@ struct nullopt_t inline constexpr nullopt_t nullopt{nullopt_t::__secret_tag{}, nullopt_t::__secret_tag{}}; +struct __optional_construct_from_invoke_tag {}; + template <class _Tp, bool = is_trivially_destructible<_Tp>::value> struct __optional_destruct_base; @@ -234,6 +249,13 @@ struct __optional_destruct_base<_Tp, false> : __val_(_VSTD::forward<_Args>(__args)...), __engaged_(true) {} +#if _LIBCPP_STD_VER > 20 + template <class _Fp, class... _Args> + _LIBCPP_HIDE_FROM_ABI + constexpr __optional_destruct_base(__optional_construct_from_invoke_tag, _Fp&& __f, _Args&&... __args) + : __val_(_VSTD::invoke(_VSTD::forward<_Fp>(__f), _VSTD::forward<_Args>(__args)...)), __engaged_(true) {} +#endif + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 void reset() noexcept { @@ -269,6 +291,13 @@ struct __optional_destruct_base<_Tp, true> : __val_(_VSTD::forward<_Args>(__args)...), __engaged_(true) {} +#if _LIBCPP_STD_VER > 20 + template <class _Fp, class... _Args> + _LIBCPP_HIDE_FROM_ABI + constexpr __optional_destruct_base(__optional_construct_from_invoke_tag, _Fp&& __f, _Args&&... __args) + : __val_(_VSTD::invoke(_VSTD::forward<_Fp>(__f), _VSTD::forward<_Args>(__args)...)), __engaged_(true) {} +#endif + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 void reset() noexcept { @@ -582,6 +611,12 @@ using __optional_sfinae_assign_base_t = __sfinae_assign_base< (is_move_constructible<_Tp>::value && is_move_assignable<_Tp>::value) >; +template<class _Tp> +class optional; +template <class _Tp> +struct __is_std_optional : false_type {}; +template <class _Tp> struct __is_std_optional<optional<_Tp>> : true_type {}; + template <class _Tp> class optional : private __optional_move_assign_base<_Tp> @@ -679,6 +714,7 @@ private: _CheckOptionalLikeConstructor<_QualUp>, __check_tuple_constructor_fail >; + public: _LIBCPP_INLINE_VISIBILITY constexpr optional() noexcept {} @@ -754,6 +790,14 @@ public: this->__construct_from(_VSTD::move(__v)); } +#if _LIBCPP_STD_VER > 20 + template<class _Fp, class... _Args> + _LIBCPP_HIDE_FROM_ABI + constexpr explicit optional(__optional_construct_from_invoke_tag, _Fp&& __f, _Args&&... __args) + : __base(__optional_construct_from_invoke_tag{}, _VSTD::forward<_Fp>(__f), _VSTD::forward<_Args>(__args)...) { + } +#endif + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 optional& operator=(nullopt_t) noexcept { @@ -988,6 +1032,132 @@ public: static_cast<value_type>(_VSTD::forward<_Up>(__v)); } +#if _LIBCPP_STD_VER > 20 + template<class _Func> + _LIBCPP_HIDE_FROM_ABI + constexpr auto and_then(_Func&& __f) & { + using _Up = invoke_result_t<_Func, value_type&>; + static_assert(__is_std_optional<remove_cvref_t<_Up>>::value, + "Result of f(value()) must be a specialization of std::optional"); + if (*this) + return _VSTD::invoke(_VSTD::forward<_Func>(__f), value()); + return remove_cvref_t<_Up>(); + } + + template<class _Func> + _LIBCPP_HIDE_FROM_ABI + constexpr auto and_then(_Func&& __f) const& { + using _Up = invoke_result_t<_Func, const value_type&>; + static_assert(__is_std_optional<remove_cvref_t<_Up>>::value, + "Result of f(value()) must be a specialization of std::optional"); + if (*this) + return _VSTD::invoke(_VSTD::forward<_Func>(__f), value()); + return remove_cvref_t<_Up>(); + } + + template<class _Func> + _LIBCPP_HIDE_FROM_ABI + constexpr auto and_then(_Func&& __f) && { + using _Up = invoke_result_t<_Func, value_type&&>; + static_assert(__is_std_optional<remove_cvref_t<_Up>>::value, + "Result of f(std::move(value())) must be a specialization of std::optional"); + if (*this) + return _VSTD::invoke(_VSTD::forward<_Func>(__f), _VSTD::move(value())); + return remove_cvref_t<_Up>(); + } + + template<class _Func> + _LIBCPP_HIDE_FROM_ABI + constexpr auto and_then(_Func&& __f) const&& { + using _Up = invoke_result_t<_Func, const value_type&&>; + static_assert(__is_std_optional<remove_cvref_t<_Up>>::value, + "Result of f(std::move(value())) must be a specialization of std::optional"); + if (*this) + return _VSTD::invoke(_VSTD::forward<_Func>(__f), _VSTD::move(value())); + return remove_cvref_t<_Up>(); + } + + template<class _Func> + _LIBCPP_HIDE_FROM_ABI + constexpr auto transform(_Func&& __f) & { + using _Up = remove_cv_t<invoke_result_t<_Func, value_type&>>; + static_assert(!is_array_v<_Up>, "Result of f(value()) should not be an Array"); + static_assert(!is_same_v<_Up, in_place_t>, + "Result of f(value()) should not be std::in_place_t"); + static_assert(!is_same_v<_Up, nullopt_t>, + "Result of f(value()) should not be std::nullopt_t"); + static_assert(is_object_v<_Up>, "Result of f(value()) should be an object type"); + if (*this) + return optional<_Up>(__optional_construct_from_invoke_tag{}, _VSTD::forward<_Func>(__f), value()); + return optional<_Up>(); + } + + template<class _Func> + _LIBCPP_HIDE_FROM_ABI + constexpr auto transform(_Func&& __f) const& { + using _Up = remove_cv_t<invoke_result_t<_Func, const value_type&>>; + static_assert(!is_array_v<_Up>, "Result of f(value()) should not be an Array"); + static_assert(!is_same_v<_Up, in_place_t>, + "Result of f(value()) should not be std::in_place_t"); + static_assert(!is_same_v<_Up, nullopt_t>, + "Result of f(value()) should not be std::nullopt_t"); + static_assert(is_object_v<_Up>, "Result of f(value()) should be an object type"); + if (*this) + return optional<_Up>(__optional_construct_from_invoke_tag{}, _VSTD::forward<_Func>(__f), value()); + return optional<_Up>(); + } + + template<class _Func> + _LIBCPP_HIDE_FROM_ABI + constexpr auto transform(_Func&& __f) && { + using _Up = remove_cv_t<invoke_result_t<_Func, value_type&&>>; + static_assert(!is_array_v<_Up>, "Result of f(std::move(value())) should not be an Array"); + static_assert(!is_same_v<_Up, in_place_t>, + "Result of f(std::move(value())) should not be std::in_place_t"); + static_assert(!is_same_v<_Up, nullopt_t>, + "Result of f(std::move(value())) should not be std::nullopt_t"); + static_assert(is_object_v<_Up>, "Result of f(std::move(value())) should be an object type"); + if (*this) + return optional<_Up>(__optional_construct_from_invoke_tag{}, _VSTD::forward<_Func>(__f), _VSTD::move(value())); + return optional<_Up>(); + } + + template<class _Func> + _LIBCPP_HIDE_FROM_ABI + constexpr auto transform(_Func&& __f) const&& { + using _Up = remove_cvref_t<invoke_result_t<_Func, const value_type&&>>; + static_assert(!is_array_v<_Up>, "Result of f(std::move(value())) should not be an Array"); + static_assert(!is_same_v<_Up, in_place_t>, + "Result of f(std::move(value())) should not be std::in_place_t"); + static_assert(!is_same_v<_Up, nullopt_t>, + "Result of f(std::move(value())) should not be std::nullopt_t"); + static_assert(is_object_v<_Up>, "Result of f(std::move(value())) should be an object type"); + if (*this) + return optional<_Up>(__optional_construct_from_invoke_tag{}, _VSTD::forward<_Func>(__f), _VSTD::move(value())); + return optional<_Up>(); + } + + template<invocable _Func> + _LIBCPP_HIDE_FROM_ABI + constexpr optional or_else(_Func&& __f) const& requires is_copy_constructible_v<value_type> { + static_assert(is_same_v<remove_cvref_t<invoke_result_t<_Func>>, optional>, + "Result of f() should be the same type as this optional"); + if (*this) + return *this; + return _VSTD::forward<_Func>(__f)(); + } + + template<invocable _Func> + _LIBCPP_HIDE_FROM_ABI + constexpr optional or_else(_Func&& __f) && requires is_move_constructible_v<value_type> { + static_assert(is_same_v<remove_cvref_t<invoke_result_t<_Func>>, optional>, + "Result of f() should be the same type as this optional"); + if (*this) + return _VSTD::move(*this); + return _VSTD::forward<_Func>(__f)(); + } +#endif // _LIBCPP_STD_VER > 20 + using __base::reset; }; diff --git a/contrib/libs/cxxsupp/libcxx/include/string b/contrib/libs/cxxsupp/libcxx/include/string index 85e0d3378d..870266c09a 100644 --- a/contrib/libs/cxxsupp/libcxx/include/string +++ b/contrib/libs/cxxsupp/libcxx/include/string @@ -843,9 +843,10 @@ public: basic_string(const _CharT* __s) : __r_(__default_init_tag(), __default_init_tag()) { _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr"); __init(__s, traits_type::length(__s)); -# if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->__insert_c(this); -# endif +#if _LIBCPP_DEBUG_LEVEL == 2 + if (!__libcpp_is_constant_evaluated()) + __get_db()->__insert_c(this); +#endif } template <class = __enable_if_t<__is_allocator<_Allocator>::value, nullptr_t> > @@ -1726,6 +1727,13 @@ private: return *this; } + _LIBCPP_HIDE_FROM_ABI basic_string& __null_terminate_at(value_type* __p, size_type __newsz) { + __set_size(__newsz); + __invalidate_iterators_past(__newsz); + traits_type::assign(__p[__newsz], value_type()); + return *this; + } + _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators(); _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(size_type); @@ -1810,7 +1818,8 @@ void basic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators() { #if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->__invalidate_all(this); + if (!__libcpp_is_constant_evaluated()) + __get_db()->__invalidate_all(this); #endif } @@ -1820,22 +1829,24 @@ void basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type __pos) { #if _LIBCPP_DEBUG_LEVEL == 2 - __c_node* __c = __get_db()->__find_c_and_lock(this); - if (__c) - { - const_pointer __new_last = __get_pointer() + __pos; - for (__i_node** __p = __c->end_; __p != __c->beg_; ) + if (!__libcpp_is_constant_evaluated()) { + __c_node* __c = __get_db()->__find_c_and_lock(this); + if (__c) { - --__p; - const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_); - if (__i->base() > __new_last) + const_pointer __new_last = __get_pointer() + __pos; + for (__i_node** __p = __c->end_; __p != __c->beg_; ) { - (*__p)->__c_ = nullptr; - if (--__c->end_ != __p) - _VSTD::memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); + --__p; + const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_); + if (__i->base() > __new_last) + { + (*__p)->__c_ = nullptr; + if (--__c->end_ != __p) + _VSTD::memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); + } } + __get_db()->unlock(); } - __get_db()->unlock(); } #else (void)__pos; @@ -1849,7 +1860,8 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string() : __r_(__default_init_tag(), __default_init_tag()) { #if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->__insert_c(this); + if (!__libcpp_is_constant_evaluated()) + __get_db()->__insert_c(this); #endif __zero(); } @@ -1865,7 +1877,8 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __ : __r_(__default_init_tag(), __a) { #if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->__insert_c(this); + if (!__libcpp_is_constant_evaluated()) + __get_db()->__insert_c(this); #endif __zero(); } @@ -1927,7 +1940,8 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, const _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr"); __init(__s, traits_type::length(__s)); #if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->__insert_c(this); + if (!__libcpp_is_constant_evaluated()) + __get_db()->__insert_c(this); #endif } @@ -1936,10 +1950,11 @@ inline basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n) : __r_(__default_init_tag(), __default_init_tag()) { - _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr"); - __init(__s, __n); + _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr"); + __init(__s, __n); #if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->__insert_c(this); + if (!__libcpp_is_constant_evaluated()) + __get_db()->__insert_c(this); #endif } @@ -1951,7 +1966,8 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_ _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr"); __init(__s, __n); #if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->__insert_c(this); + if (!__libcpp_is_constant_evaluated()) + __get_db()->__insert_c(this); #endif } @@ -1966,7 +1982,8 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __st __str.__get_long_size()); #if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->__insert_c(this); + if (!__libcpp_is_constant_evaluated()) + __get_db()->__insert_c(this); #endif } @@ -1981,7 +1998,8 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string( __init_copy_ctor_external(_VSTD::__to_address(__str.__get_long_pointer()), __str.__get_long_size()); #if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->__insert_c(this); + if (!__libcpp_is_constant_evaluated()) + __get_db()->__insert_c(this); #endif } @@ -2018,9 +2036,11 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str) { __str.__zero(); #if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->__insert_c(this); - if (__is_long()) - __get_db()->swap(this, &__str); + if (!__libcpp_is_constant_evaluated()) { + __get_db()->__insert_c(this); + if (__is_long()) + __get_db()->swap(this, &__str); + } #endif } @@ -2037,9 +2057,11 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, co __str.__zero(); } #if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->__insert_c(this); - if (__is_long()) - __get_db()->swap(this, &__str); + if (!__libcpp_is_constant_evaluated()) { + __get_db()->__insert_c(this); + if (__is_long()) + __get_db()->swap(this, &__str); + } #endif } @@ -2076,7 +2098,8 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __ { __init(__n, __c); #if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->__insert_c(this); + if (!__libcpp_is_constant_evaluated()) + __get_db()->__insert_c(this); #endif } @@ -2087,7 +2110,8 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __ { __init(__n, __c); #if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->__insert_c(this); + if (!__libcpp_is_constant_evaluated()) + __get_db()->__insert_c(this); #endif } @@ -2102,7 +2126,8 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __st this->__throw_out_of_range(); __init(__str.data() + __pos, _VSTD::min(__n, __str_sz - __pos)); #if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->__insert_c(this); + if (!__libcpp_is_constant_evaluated()) + __get_db()->__insert_c(this); #endif } @@ -2117,7 +2142,8 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __st this->__throw_out_of_range(); __init(__str.data() + __pos, __str_sz - __pos); #if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->__insert_c(this); + if (!__libcpp_is_constant_evaluated()) + __get_db()->__insert_c(this); #endif } @@ -2131,7 +2157,8 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string( __self_view __sv = __sv0.substr(__pos, __n); __init(__sv.data(), __sv.size()); #if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->__insert_c(this); + if (!__libcpp_is_constant_evaluated()) + __get_db()->__insert_c(this); #endif } @@ -2143,7 +2170,8 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t) __self_view __sv = __t; __init(__sv.data(), __sv.size()); #if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->__insert_c(this); + if (!__libcpp_is_constant_evaluated()) + __get_db()->__insert_c(this); #endif } @@ -2155,7 +2183,8 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t, const _ __self_view __sv = __t; __init(__sv.data(), __sv.size()); #if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->__insert_c(this); + if (!__libcpp_is_constant_evaluated()) + __get_db()->__insert_c(this); #endif } @@ -2237,7 +2266,8 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, { __init(__first, __last); #if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->__insert_c(this); + if (!__libcpp_is_constant_evaluated()) + __get_db()->__insert_c(this); #endif } @@ -2250,7 +2280,8 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, { __init(__first, __last); #if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->__insert_c(this); + if (!__libcpp_is_constant_evaluated()) + __get_db()->__insert_c(this); #endif } @@ -2264,7 +2295,8 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string( { __init(__il.begin(), __il.end()); #if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->__insert_c(this); + if (!__libcpp_is_constant_evaluated()) + __get_db()->__insert_c(this); #endif } @@ -2277,7 +2309,8 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string( { __init(__il.begin(), __il.end()); #if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->__insert_c(this); + if (!__libcpp_is_constant_evaluated()) + __get_db()->__insert_c(this); #endif } @@ -2287,7 +2320,8 @@ template <class _CharT, class _Traits, class _Allocator> basic_string<_CharT, _Traits, _Allocator>::~basic_string() { #if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->__erase_c(this); + if (!__libcpp_is_constant_evaluated()) + __get_db()->__erase_c(this); #endif if (__is_long()) __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap()); @@ -2383,14 +2417,12 @@ basic_string<_CharT, _Traits, _Allocator>::__assign_external( if (__cap >= __n) { value_type* __p = _VSTD::__to_address(__get_pointer()); traits_type::move(__p, __s, __n); - traits_type::assign(__p[__n], value_type()); - __set_size(__n); - __invalidate_iterators_past(__n); + return __null_terminate_at(__p, __n); } else { size_type __sz = size(); __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s); + return *this; } - return *this; } template <class _CharT, class _Traits, class _Allocator> @@ -2415,10 +2447,7 @@ basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c) } value_type* __p = _VSTD::__to_address(__get_pointer()); traits_type::assign(__p, __n, __c); - traits_type::assign(__p[__n], value_type()); - __set_size(__n); - __invalidate_iterators_past(__n); - return *this; + return __null_terminate_at(__p, __n); } template <class _CharT, class _Traits, class _Allocator> @@ -2858,13 +2887,11 @@ __enable_if_t > basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last) { -#if _LIBCPP_DEBUG_LEVEL == 2 - _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this, - "string::insert(iterator, range) called with an iterator not" - " referring to this string"); -#endif - const basic_string __temp(__first, __last, __alloc()); - return insert(__pos, __temp.data(), __temp.data() + __temp.size()); + _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this, + "string::insert(iterator, range) called with an iterator not" + " referring to this string"); + const basic_string __temp(__first, __last, __alloc()); + return insert(__pos, __temp.data(), __temp.data() + __temp.size()); } template <class _CharT, class _Traits, class _Allocator> @@ -2876,11 +2903,10 @@ __enable_if_t > basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last) { -#if _LIBCPP_DEBUG_LEVEL == 2 - _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this, - "string::insert(iterator, range) called with an iterator not" - " referring to this string"); -#endif + _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this, + "string::insert(iterator, range) called with an iterator not" + " referring to this string"); + size_type __ip = static_cast<size_type>(__pos - begin()); size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last)); if (__n) @@ -2993,14 +3019,12 @@ inline typename basic_string<_CharT, _Traits, _Allocator>::iterator basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c) { -#if _LIBCPP_DEBUG_LEVEL == 2 - _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this, - "string::insert(iterator, n, value) called with an iterator not" - " referring to this string"); -#endif - difference_type __p = __pos - begin(); - insert(static_cast<size_type>(__p), __n, __c); - return begin() + __p; + _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this, + "string::insert(iterator, n, value) called with an iterator not" + " referring to this string"); + difference_type __p = __pos - begin(); + insert(static_cast<size_type>(__p), __n, __c); + return begin() + __p; } // replace @@ -3028,7 +3052,7 @@ basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __ { traits_type::move(__p + __pos, __s, __n2); traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move); - goto __finish; + return __null_terminate_at(__p, __sz + (__n2 - __n1)); } if (__p + __pos < __s && __s < __p + __sz) { @@ -3047,13 +3071,7 @@ basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __ } } traits_type::move(__p + __pos, __s, __n2); -__finish: -// __sz += __n2 - __n1; in this and the below function below can cause unsigned -// integer overflow, but this is a safe operation, so we disable the check. - __sz += __n2 - __n1; - __set_size(__sz); - __invalidate_iterators_past(__sz); - traits_type::assign(__p[__sz], value_type()); + return __null_terminate_at(__p, __sz + (__n2 - __n1)); } else __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s); @@ -3063,7 +3081,6 @@ __finish: template <class _CharT, class _Traits, class _Allocator> basic_string<_CharT, _Traits, _Allocator>& basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c) - _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK { size_type __sz = size(); if (__pos > __sz) @@ -3087,11 +3104,7 @@ basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __ __p = _VSTD::__to_address(__get_long_pointer()); } traits_type::assign(__p + __pos, __n2, __c); - __sz += __n2 - __n1; - __set_size(__sz); - __invalidate_iterators_past(__sz); - traits_type::assign(__p[__sz], value_type()); - return *this; + return __null_terminate_at(__p, __sz - (__n1 - __n2)); } template <class _CharT, class _Traits, class _Allocator> @@ -3202,10 +3215,7 @@ basic_string<_CharT, _Traits, _Allocator>::__erase_external_with_move( size_type __n_move = __sz - __pos - __n; if (__n_move != 0) traits_type::move(__p + __pos, __p + __pos + __n, __n_move); - __sz -= __n; - __set_size(__sz); - __invalidate_iterators_past(__sz); - traits_type::assign(__p[__sz], value_type()); + __null_terminate_at(__p, __sz - __n); } } @@ -3227,17 +3237,15 @@ inline typename basic_string<_CharT, _Traits, _Allocator>::iterator basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos) { -#if _LIBCPP_DEBUG_LEVEL == 2 - _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this, - "string::erase(iterator) called with an iterator not" - " referring to this string"); -#endif - _LIBCPP_ASSERT(__pos != end(), - "string::erase(iterator) called with a non-dereferenceable iterator"); - iterator __b = begin(); - size_type __r = static_cast<size_type>(__pos - __b); - erase(__r, 1); - return __b + static_cast<difference_type>(__r); + _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this, + "string::erase(iterator) called with an iterator not" + " referring to this string"); + + _LIBCPP_ASSERT(__pos != end(), "string::erase(iterator) called with a non-dereferenceable iterator"); + iterator __b = begin(); + size_type __r = static_cast<size_type>(__pos - __b); + erase(__r, 1); + return __b + static_cast<difference_type>(__r); } template <class _CharT, class _Traits, class _Allocator> @@ -3245,16 +3253,15 @@ inline typename basic_string<_CharT, _Traits, _Allocator>::iterator basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last) { -#if _LIBCPP_DEBUG_LEVEL == 2 - _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this, - "string::erase(iterator, iterator) called with an iterator not" - " referring to this string"); -#endif - _LIBCPP_ASSERT(__first <= __last, "string::erase(first, last) called with invalid range"); - iterator __b = begin(); - size_type __r = static_cast<size_type>(__first - __b); - erase(__r, static_cast<size_type>(__last - __first)); - return __b + static_cast<difference_type>(__r); + _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this, + "string::erase(iterator, iterator) called with an iterator not" + " referring to this string"); + + _LIBCPP_ASSERT(__first <= __last, "string::erase(first, last) called with invalid range"); + iterator __b = begin(); + size_type __r = static_cast<size_type>(__first - __b); + erase(__r, static_cast<size_type>(__last - __first)); + return __b + static_cast<difference_type>(__r); } template <class _CharT, class _Traits, class _Allocator> @@ -3263,20 +3270,7 @@ void basic_string<_CharT, _Traits, _Allocator>::pop_back() { _LIBCPP_ASSERT(!empty(), "string::pop_back(): string is already empty"); - size_type __sz; - if (__is_long()) - { - __sz = __get_long_size() - 1; - __set_long_size(__sz); - traits_type::assign(*(__get_long_pointer() + __sz), value_type()); - } - else - { - __sz = __get_short_size() - 1; - __set_short_size(__sz); - traits_type::assign(*(__get_short_pointer() + __sz), value_type()); - } - __invalidate_iterators_past(__sz); + __erase_to_end(size() - 1); } template <class _CharT, class _Traits, class _Allocator> @@ -3302,17 +3296,7 @@ inline void basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos) { - if (__is_long()) - { - traits_type::assign(*(__get_long_pointer() + __pos), value_type()); - __set_long_size(__pos); - } - else - { - traits_type::assign(*(__get_short_pointer() + __pos), value_type()); - __set_short_size(__pos); - } - __invalidate_iterators_past(__pos); + __null_terminate_at(_VSTD::__to_address(__get_pointer()), __pos); } template <class _CharT, class _Traits, class _Allocator> @@ -3370,6 +3354,7 @@ basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __requested_capacit } template <class _CharT, class _Traits, class _Allocator> +inline void basic_string<_CharT, _Traits, _Allocator>::shrink_to_fit() _NOEXCEPT { @@ -3380,6 +3365,7 @@ basic_string<_CharT, _Traits, _Allocator>::shrink_to_fit() _NOEXCEPT } template <class _CharT, class _Traits, class _Allocator> +inline void basic_string<_CharT, _Traits, _Allocator>::__shrink_or_extend(size_type __target_capacity) { @@ -3540,11 +3526,13 @@ basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str) #endif { #if _LIBCPP_DEBUG_LEVEL == 2 - if (!__is_long()) - __get_db()->__invalidate_all(this); - if (!__str.__is_long()) - __get_db()->__invalidate_all(&__str); - __get_db()->swap(this, &__str); + if (!__libcpp_is_constant_evaluated()) { + if (!__is_long()) + __get_db()->__invalidate_all(this); + if (!__str.__is_long()) + __get_db()->__invalidate_all(&__str); + __get_db()->swap(this, &__str); + } #endif _LIBCPP_ASSERT( __alloc_traits::propagate_on_container_swap::value || diff --git a/contrib/libs/cxxsupp/libcxx/include/type_traits b/contrib/libs/cxxsupp/libcxx/include/type_traits index 760ddc5d12..170ed6a49b 100644 --- a/contrib/libs/cxxsupp/libcxx/include/type_traits +++ b/contrib/libs/cxxsupp/libcxx/include/type_traits @@ -598,6 +598,12 @@ inline constexpr bool is_same_v = is_same<_Tp, _Up>::value; #endif #endif // __is_same +// _IsSame<T,U> has the same effect as is_same<T,U> but instantiates fewer types: +// is_same<A,B> and is_same<C,D> are guaranteed to be different types, but +// _IsSame<A,B> and _IsSame<C,D> are the same type (namely, false_type). +// Neither GCC nor Clang can mangle the __is_same builtin, so _IsSame +// mustn't be directly used anywhere that contributes to name-mangling +// (such as in a dependent return type). template <class _Tp, class _Up> using _IsSame = _BoolConstant< @@ -627,9 +633,9 @@ using __is_primary_template = _IsValidExpansion< __test_for_primary_template, _Tp >; -struct __two {char __lx[2];}; +// helper class -// helper class: +struct __two {char __lx[2];}; // is_const diff --git a/contrib/libs/cxxsupp/libcxx/include/utility b/contrib/libs/cxxsupp/libcxx/include/utility index ac8470e269..9ab7b8e0ff 100644 --- a/contrib/libs/cxxsupp/libcxx/include/utility +++ b/contrib/libs/cxxsupp/libcxx/include/utility @@ -231,6 +231,7 @@ template <class T> #include <__utility/rel_ops.h> #include <__utility/swap.h> #include <__utility/to_underlying.h> +#include <__utility/transaction.h> #include <compare> #include <initializer_list> #include <version> diff --git a/contrib/libs/cxxsupp/libcxx/include/version b/contrib/libs/cxxsupp/libcxx/include/version index f69d85889a..a78aa0a3bd 100644 --- a/contrib/libs/cxxsupp/libcxx/include/version +++ b/contrib/libs/cxxsupp/libcxx/include/version @@ -109,6 +109,7 @@ __cpp_lib_map_try_emplace 201411L <map> __cpp_lib_math_constants 201907L <numbers> __cpp_lib_math_special_functions 201603L <cmath> __cpp_lib_memory_resource 201603L <memory_resource> +__cpp_lib_monadic_optional 202110L <optional> __cpp_lib_node_extract 201606L <map> <set> <unordered_map> <unordered_set> __cpp_lib_nonmember_container_access 201411L <array> <deque> <forward_list> @@ -355,6 +356,7 @@ __cpp_lib_void_t 201411L <type_traits> #if _LIBCPP_STD_VER > 20 # define __cpp_lib_byteswap 202110L # define __cpp_lib_is_scoped_enum 202011L +# define __cpp_lib_monadic_optional 202110L // # define __cpp_lib_stacktrace 202011L // # define __cpp_lib_stdatomic_h 202011L # define __cpp_lib_string_contains 202011L diff --git a/contrib/libs/cxxsupp/libcxx/src/barrier.cpp b/contrib/libs/cxxsupp/libcxx/src/barrier.cpp index 0f9dad987f..54890b2d79 100644 --- a/contrib/libs/cxxsupp/libcxx/src/barrier.cpp +++ b/contrib/libs/cxxsupp/libcxx/src/barrier.cpp @@ -15,14 +15,14 @@ _LIBCPP_BEGIN_NAMESPACE_STD -#if !defined(_LIBCPP_HAS_NO_TREE_BARRIER) && (_LIBCPP_STD_VER > 11) +#if !defined(_LIBCPP_HAS_NO_TREE_BARRIER) class __barrier_algorithm_base { public: struct alignas(64) /* naturally-align the heap state */ __state_t { struct { - __atomic_base<__barrier_phase_t> __phase = ATOMIC_VAR_INIT(0); + __atomic_base<__barrier_phase_t> __phase{0}; } __tickets[64]; }; @@ -90,7 +90,7 @@ void __destroy_barrier_algorithm_base(__barrier_algorithm_base* __barrier) delete __barrier; } -#endif //!defined(_LIBCPP_HAS_NO_TREE_BARRIER) && (_LIBCPP_STD_VER >= 11) +#endif //!defined(_LIBCPP_HAS_NO_TREE_BARRIER) _LIBCPP_END_NAMESPACE_STD diff --git a/contrib/libs/cxxsupp/libcxx/src/chrono.cpp b/contrib/libs/cxxsupp/libcxx/src/chrono.cpp index b16bf97241..5aa7af7589 100644 --- a/contrib/libs/cxxsupp/libcxx/src/chrono.cpp +++ b/contrib/libs/cxxsupp/libcxx/src/chrono.cpp @@ -80,13 +80,9 @@ public: GetSystemTimeAsFileTimePtr fp; }; -#ifndef _LIBCPP_COMPILER_MSVC -# 83 "chrono.cpp" 1 3 -#endif -GetSystemTimeInit GetSystemTimeAsFileTimeFunc _LIBCPP_INIT_PRIORITY_MAX; -#ifndef _LIBCPP_COMPILER_MSVC -# 85 "chrono.cpp" 2 -#endif +// Pretend we're inside a system header so the compiler doesn't flag the use of the init_priority +// attribute with a value that's reserved for the implementation (we're the implementation). +#include "chrono_system_time_init.h" } // namespace #endif diff --git a/contrib/libs/cxxsupp/libcxx/src/chrono_system_time_init.h b/contrib/libs/cxxsupp/libcxx/src/chrono_system_time_init.h new file mode 100644 index 0000000000..3c5a0c33a5 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxx/src/chrono_system_time_init.h @@ -0,0 +1,2 @@ +#pragma GCC system_header +GetSystemTimeInit GetSystemTimeAsFileTimeFunc _LIBCPP_INIT_PRIORITY_MAX;
\ No newline at end of file diff --git a/contrib/libs/cxxsupp/libcxx/src/experimental/memory_resource.cpp b/contrib/libs/cxxsupp/libcxx/src/experimental/memory_resource.cpp index be2fb47fad..018d015928 100644 --- a/contrib/libs/cxxsupp/libcxx/src/experimental/memory_resource.cpp +++ b/contrib/libs/cxxsupp/libcxx/src/experimental/memory_resource.cpp @@ -76,9 +76,9 @@ union ResourceInitHelper { ~ResourceInitHelper() {} }; -# 79 "memory_resource.cpp" 1 3 -_LIBCPP_SAFE_STATIC ResourceInitHelper res_init _LIBCPP_INIT_PRIORITY_MAX; -# 81 "memory_resource.cpp" 2 +// Pretend we're inside a system header so the compiler doesn't flag the use of the init_priority +// attribute with a value that's reserved for the implementation (we're the implementation). +#include "memory_resource_init_helper.h" } // end namespace @@ -97,8 +97,7 @@ static memory_resource * __default_memory_resource(bool set = false, memory_resource * new_res = nullptr) noexcept { #ifndef _LIBCPP_HAS_NO_ATOMIC_HEADER - _LIBCPP_SAFE_STATIC static atomic<memory_resource*> __res = - ATOMIC_VAR_INIT(&res_init.resources.new_delete_res); + _LIBCPP_SAFE_STATIC static atomic<memory_resource*> __res{&res_init.resources.new_delete_res}; if (set) { new_res = new_res ? new_res : new_delete_resource(); // TODO: Can a weaker ordering be used? diff --git a/contrib/libs/cxxsupp/libcxx/src/experimental/memory_resource_init_helper.h b/contrib/libs/cxxsupp/libcxx/src/experimental/memory_resource_init_helper.h new file mode 100644 index 0000000000..2e1cae5ecc --- /dev/null +++ b/contrib/libs/cxxsupp/libcxx/src/experimental/memory_resource_init_helper.h @@ -0,0 +1,2 @@ +#pragma GCC system_header +_LIBCPP_SAFE_STATIC ResourceInitHelper res_init _LIBCPP_INIT_PRIORITY_MAX;
\ No newline at end of file diff --git a/contrib/libs/cxxsupp/libcxx/src/format.cpp b/contrib/libs/cxxsupp/libcxx/src/format.cpp index 7ae2af59b7..2ebec28247 100644 --- a/contrib/libs/cxxsupp/libcxx/src/format.cpp +++ b/contrib/libs/cxxsupp/libcxx/src/format.cpp @@ -10,10 +10,6 @@ _LIBCPP_BEGIN_NAMESPACE_STD -#if _LIBCPP_STD_VER > 17 - format_error::~format_error() noexcept = default; -#endif //_LIBCPP_STD_VER > 17 - _LIBCPP_END_NAMESPACE_STD diff --git a/contrib/libs/cxxsupp/libcxx/src/ios.cpp b/contrib/libs/cxxsupp/libcxx/src/ios.cpp index a9bd1dc323..56fbcca417 100644 --- a/contrib/libs/cxxsupp/libcxx/src/ios.cpp +++ b/contrib/libs/cxxsupp/libcxx/src/ios.cpp @@ -137,7 +137,7 @@ ios_base::getloc() const // xalloc #if defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_NO_THREADS) -atomic<int> ios_base::__xindex_ = ATOMIC_VAR_INIT(0); +atomic<int> ios_base::__xindex_{0}; #else int ios_base::__xindex_ = 0; #endif diff --git a/contrib/libs/cxxsupp/libcxx/src/iostream.cpp b/contrib/libs/cxxsupp/libcxx/src/iostream.cpp index 296b5c3f2c..71c8dda834 100644 --- a/contrib/libs/cxxsupp/libcxx/src/iostream.cpp +++ b/contrib/libs/cxxsupp/libcxx/src/iostream.cpp @@ -125,16 +125,9 @@ __asm__("?wclog@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@_WU?$char_t #endif #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS -// Hacky way to make the compiler believe that we're inside a system header so -// it doesn't flag the use of the init_priority attribute with a value that's -// reserved for the implementation (we're the implementation). -#ifndef _LIBCPP_COMPILER_MSVC -# 80 "iostream.cpp" 1 3 -#endif -_LIBCPP_HIDDEN ios_base::Init __start_std_streams _LIBCPP_INIT_PRIORITY_MAX; -#ifndef _LIBCPP_COMPILER_MSVC -# 82 "iostream.cpp" 2 -#endif +// Pretend we're inside a system header so the compiler doesn't flag the use of the init_priority +// attribute with a value that's reserved for the implementation (we're the implementation). +#include "iostream_init.h" // On Windows the TLS storage for locales needs to be initialized before we create // the standard streams, otherwise it may not be alive during program termination diff --git a/contrib/libs/cxxsupp/libcxx/src/iostream_init.h b/contrib/libs/cxxsupp/libcxx/src/iostream_init.h new file mode 100644 index 0000000000..b0a60f42a6 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxx/src/iostream_init.h @@ -0,0 +1,2 @@ +#pragma GCC system_header +_LIBCPP_HIDDEN ios_base::Init __start_std_streams _LIBCPP_INIT_PRIORITY_MAX;
\ No newline at end of file diff --git a/contrib/libs/cxxsupp/libcxx/src/random.cpp b/contrib/libs/cxxsupp/libcxx/src/random.cpp index 83b98c68f4..c4bda825fb 100644 --- a/contrib/libs/cxxsupp/libcxx/src/random.cpp +++ b/contrib/libs/cxxsupp/libcxx/src/random.cpp @@ -9,8 +9,8 @@ #include <__config> #if defined(_LIBCPP_USING_WIN32_RANDOM) -// Must be defined before including stdlib.h to enable rand_s(). -#define _CRT_RAND_S + // Must be defined before including stdlib.h to enable rand_s(). +# define _CRT_RAND_S #endif // defined(_LIBCPP_USING_WIN32_RANDOM) #include "limits" @@ -18,7 +18,7 @@ #include "system_error" #if defined(__sun__) -#define rename solaris_headers_are_broken +# define rename solaris_headers_are_broken #endif // defined(__sun__) #include <errno.h> @@ -26,16 +26,16 @@ #include <stdlib.h> #if defined(_LIBCPP_USING_GETENTROPY) -#include <sys/random.h> +# include <sys/random.h> #elif defined(_LIBCPP_USING_DEV_RANDOM) -#include <fcntl.h> -#include <unistd.h> -#if __has_include(<sys/ioctl.h>) && __has_include(<linux/random.h>) -#include <sys/ioctl.h> -#include <linux/random.h> -#endif +# include <fcntl.h> +# include <unistd.h> +# if __has_include(<sys/ioctl.h>) && __has_include(<linux/random.h>) +# include <sys/ioctl.h> +# include <linux/random.h> +# endif #elif defined(_LIBCPP_USING_NACL_RANDOM) -#include <nacl/nacl_random.h> +# include <nacl/nacl_random.h> #endif |