From 3ad39e9878310e5317ee73c9b353c1e2c1c5c4ee Mon Sep 17 00:00:00 2001 From: Richard Qin Date: Sat, 11 Jul 2026 22:48:30 +0800 Subject: lib: establish Zircon libc++ and KTL foundation --- .../libcxx/include/c++/v1/__utility/as_const.h | 32 + .../libcxx/include/c++/v1/__utility/as_lvalue.h | 37 ++ .../libcxx/include/c++/v1/__utility/auto_cast.h | 22 + third_party/libcxx/include/c++/v1/__utility/cmp.h | 93 +++ .../include/c++/v1/__utility/convert_to_integral.h | 68 ++ .../libcxx/include/c++/v1/__utility/declval.h | 38 ++ .../v1/__utility/default_three_way_comparator.h | 70 +++ .../include/c++/v1/__utility/element_count.h | 27 + .../libcxx/include/c++/v1/__utility/empty.h | 24 + .../include/c++/v1/__utility/exception_guard.h | 143 +++++ .../libcxx/include/c++/v1/__utility/exchange.h | 41 ++ .../libcxx/include/c++/v1/__utility/forward.h | 38 ++ .../libcxx/include/c++/v1/__utility/forward_like.h | 63 ++ .../libcxx/include/c++/v1/__utility/in_place.h | 64 ++ .../include/c++/v1/__utility/integer_sequence.h | 105 ++++ .../include/c++/v1/__utility/is_pointer_in_range.h | 70 +++ .../v1/__utility/lazy_synth_three_way_comparator.h | 120 ++++ third_party/libcxx/include/c++/v1/__utility/move.h | 49 ++ .../libcxx/include/c++/v1/__utility/no_destroy.h | 53 ++ third_party/libcxx/include/c++/v1/__utility/pair.h | 689 +++++++++++++++++++++ .../include/c++/v1/__utility/piecewise_construct.h | 32 + .../libcxx/include/c++/v1/__utility/priority_tag.h | 28 + .../c++/v1/__utility/private_constructor_tag.h | 28 + .../libcxx/include/c++/v1/__utility/rel_ops.h | 46 ++ .../libcxx/include/c++/v1/__utility/scope_guard.h | 57 ++ .../libcxx/include/c++/v1/__utility/small_buffer.h | 101 +++ third_party/libcxx/include/c++/v1/__utility/swap.h | 60 ++ .../include/c++/v1/__utility/to_underlying.h | 38 ++ .../include/c++/v1/__utility/try_key_extraction.h | 114 ++++ .../libcxx/include/c++/v1/__utility/unreachable.h | 34 + 30 files changed, 2384 insertions(+) create mode 100644 third_party/libcxx/include/c++/v1/__utility/as_const.h create mode 100644 third_party/libcxx/include/c++/v1/__utility/as_lvalue.h create mode 100644 third_party/libcxx/include/c++/v1/__utility/auto_cast.h create mode 100644 third_party/libcxx/include/c++/v1/__utility/cmp.h create mode 100644 third_party/libcxx/include/c++/v1/__utility/convert_to_integral.h create mode 100644 third_party/libcxx/include/c++/v1/__utility/declval.h create mode 100644 third_party/libcxx/include/c++/v1/__utility/default_three_way_comparator.h create mode 100644 third_party/libcxx/include/c++/v1/__utility/element_count.h create mode 100644 third_party/libcxx/include/c++/v1/__utility/empty.h create mode 100644 third_party/libcxx/include/c++/v1/__utility/exception_guard.h create mode 100644 third_party/libcxx/include/c++/v1/__utility/exchange.h create mode 100644 third_party/libcxx/include/c++/v1/__utility/forward.h create mode 100644 third_party/libcxx/include/c++/v1/__utility/forward_like.h create mode 100644 third_party/libcxx/include/c++/v1/__utility/in_place.h create mode 100644 third_party/libcxx/include/c++/v1/__utility/integer_sequence.h create mode 100644 third_party/libcxx/include/c++/v1/__utility/is_pointer_in_range.h create mode 100644 third_party/libcxx/include/c++/v1/__utility/lazy_synth_three_way_comparator.h create mode 100644 third_party/libcxx/include/c++/v1/__utility/move.h create mode 100644 third_party/libcxx/include/c++/v1/__utility/no_destroy.h create mode 100644 third_party/libcxx/include/c++/v1/__utility/pair.h create mode 100644 third_party/libcxx/include/c++/v1/__utility/piecewise_construct.h create mode 100644 third_party/libcxx/include/c++/v1/__utility/priority_tag.h create mode 100644 third_party/libcxx/include/c++/v1/__utility/private_constructor_tag.h create mode 100644 third_party/libcxx/include/c++/v1/__utility/rel_ops.h create mode 100644 third_party/libcxx/include/c++/v1/__utility/scope_guard.h create mode 100644 third_party/libcxx/include/c++/v1/__utility/small_buffer.h create mode 100644 third_party/libcxx/include/c++/v1/__utility/swap.h create mode 100644 third_party/libcxx/include/c++/v1/__utility/to_underlying.h create mode 100644 third_party/libcxx/include/c++/v1/__utility/try_key_extraction.h create mode 100644 third_party/libcxx/include/c++/v1/__utility/unreachable.h (limited to 'third_party/libcxx/include/c++/v1/__utility') diff --git a/third_party/libcxx/include/c++/v1/__utility/as_const.h b/third_party/libcxx/include/c++/v1/__utility/as_const.h new file mode 100644 index 0000000..0f54b98 --- /dev/null +++ b/third_party/libcxx/include/c++/v1/__utility/as_const.h @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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_AS_CONST_H +#define _LIBCPP___UTILITY_AS_CONST_H + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if _LIBCPP_STD_VER >= 17 +template +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr const _Tp& as_const(_Tp& __t) noexcept { + return __t; +} + +template +void as_const(const _Tp&&) = delete; +#endif + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___UTILITY_AS_CONST_H diff --git a/third_party/libcxx/include/c++/v1/__utility/as_lvalue.h b/third_party/libcxx/include/c++/v1/__utility/as_lvalue.h new file mode 100644 index 0000000..159f45d --- /dev/null +++ b/third_party/libcxx/include/c++/v1/__utility/as_lvalue.h @@ -0,0 +1,37 @@ +// -*- 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___UTILITY_AS_LVALUE_H +#define _LIBCPP___UTILITY_AS_LVALUE_H + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +#ifndef _LIBCPP_CXX03_LANG + +template +_LIBCPP_HIDE_FROM_ABI constexpr _Tp& __as_lvalue(_LIBCPP_LIFETIMEBOUND _Tp&& __t) { + return static_cast<_Tp&>(__t); +} + +#endif // !_LIBCPP_CXX03_LANG + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___UTILITY_AS_LVALUE_H diff --git a/third_party/libcxx/include/c++/v1/__utility/auto_cast.h b/third_party/libcxx/include/c++/v1/__utility/auto_cast.h new file mode 100644 index 0000000..06715b3 --- /dev/null +++ b/third_party/libcxx/include/c++/v1/__utility/auto_cast.h @@ -0,0 +1,22 @@ +// -*- 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___UTILITY_AUTO_CAST_H +#define _LIBCPP___UTILITY_AUTO_CAST_H + +#include <__config> +#include <__type_traits/decay.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +#define _LIBCPP_AUTO_CAST(expr) static_cast<::std::__decay_t >(expr) + +#endif // _LIBCPP___UTILITY_AUTO_CAST_H diff --git a/third_party/libcxx/include/c++/v1/__utility/cmp.h b/third_party/libcxx/include/c++/v1/__utility/cmp.h new file mode 100644 index 0000000..7cfe640 --- /dev/null +++ b/third_party/libcxx/include/c++/v1/__utility/cmp.h @@ -0,0 +1,93 @@ +//===----------------------------------------------------------------------===// +// +// 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_CMP_H +#define _LIBCPP___UTILITY_CMP_H + +#include <__config> +#include <__type_traits/integer_traits.h> +#include <__type_traits/is_signed.h> +#include <__type_traits/make_unsigned.h> +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if _LIBCPP_STD_VER >= 20 + +template +concept __comparison_can_promote_to = + sizeof(_Tp) < sizeof(_Ip) || (sizeof(_Tp) == sizeof(_Ip) && __signed_integer<_Tp>); + +template <__signed_or_unsigned_integer _Tp, __signed_or_unsigned_integer _Up> +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool cmp_equal(_Tp __t, _Up __u) noexcept { + if constexpr (is_signed_v<_Tp> == is_signed_v<_Up>) + return __t == __u; + else if constexpr (__comparison_can_promote_to<_Tp, int> && __comparison_can_promote_to<_Up, int>) + return static_cast(__t) == static_cast(__u); + else if constexpr (__comparison_can_promote_to<_Tp, long long> && __comparison_can_promote_to<_Up, long long>) + return static_cast(__t) == static_cast(__u); + else if constexpr (is_signed_v<_Tp>) + return __t < 0 ? false : make_unsigned_t<_Tp>(__t) == __u; + else + return __u < 0 ? false : __t == make_unsigned_t<_Up>(__u); +} + +template <__signed_or_unsigned_integer _Tp, __signed_or_unsigned_integer _Up> +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool cmp_not_equal(_Tp __t, _Up __u) noexcept { + return !std::cmp_equal(__t, __u); +} + +template <__signed_or_unsigned_integer _Tp, __signed_or_unsigned_integer _Up> +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool cmp_less(_Tp __t, _Up __u) noexcept { + if constexpr (is_signed_v<_Tp> == is_signed_v<_Up>) + return __t < __u; + else if constexpr (__comparison_can_promote_to<_Tp, int> && __comparison_can_promote_to<_Up, int>) + return static_cast(__t) < static_cast(__u); + else if constexpr (__comparison_can_promote_to<_Tp, long long> && __comparison_can_promote_to<_Up, long long>) + return static_cast(__t) < static_cast(__u); + else if constexpr (is_signed_v<_Tp>) + return __t < 0 ? true : make_unsigned_t<_Tp>(__t) < __u; + else + return __u < 0 ? false : __t < make_unsigned_t<_Up>(__u); +} + +template <__signed_or_unsigned_integer _Tp, __signed_or_unsigned_integer _Up> +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool cmp_greater(_Tp __t, _Up __u) noexcept { + return std::cmp_less(__u, __t); +} + +template <__signed_or_unsigned_integer _Tp, __signed_or_unsigned_integer _Up> +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool cmp_less_equal(_Tp __t, _Up __u) noexcept { + return !std::cmp_greater(__t, __u); +} + +template <__signed_or_unsigned_integer _Tp, __signed_or_unsigned_integer _Up> +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool cmp_greater_equal(_Tp __t, _Up __u) noexcept { + return !std::cmp_less(__t, __u); +} + +template <__signed_or_unsigned_integer _Tp, __signed_or_unsigned_integer _Up> +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool in_range(_Up __u) noexcept { + return std::cmp_less_equal(__u, numeric_limits<_Tp>::max()) && + std::cmp_greater_equal(__u, numeric_limits<_Tp>::min()); +} + +#endif // _LIBCPP_STD_VER >= 20 + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___UTILITY_CMP_H diff --git a/third_party/libcxx/include/c++/v1/__utility/convert_to_integral.h b/third_party/libcxx/include/c++/v1/__utility/convert_to_integral.h new file mode 100644 index 0000000..c8149b7 --- /dev/null +++ b/third_party/libcxx/include/c++/v1/__utility/convert_to_integral.h @@ -0,0 +1,68 @@ +//===----------------------------------------------------------------------===// +// +// 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_CONVERT_TO_INTEGRAL_H +#define _LIBCPP___UTILITY_CONVERT_TO_INTEGRAL_H + +#include <__config> +#include <__type_traits/enable_if.h> +#include <__type_traits/is_enum.h> +#include <__type_traits/is_floating_point.h> +#include <__type_traits/underlying_type.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __convert_to_integral(int __val) { return __val; } + +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR unsigned __convert_to_integral(unsigned __val) { return __val; } + +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR long __convert_to_integral(long __val) { return __val; } + +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR unsigned long __convert_to_integral(unsigned long __val) { + return __val; +} + +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR long long __convert_to_integral(long long __val) { return __val; } + +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR unsigned long long __convert_to_integral(unsigned long long __val) { + return __val; +} + +template ::value, int> = 0> +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR long long __convert_to_integral(_Fp __val) { + return __val; +} + +#if _LIBCPP_HAS_INT128 +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __int128_t __convert_to_integral(__int128_t __val) { return __val; } + +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __uint128_t __convert_to_integral(__uint128_t __val) { return __val; } +#endif + +template ::value> +struct __sfinae_underlying_type { + using type = __underlying_type_t<_Tp>; + typedef decltype(((type)1) + 0) __promoted_type; +}; + +template +struct __sfinae_underlying_type<_Tp, false> {}; + +template +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR typename __sfinae_underlying_type<_Tp>::__promoted_type +__convert_to_integral(_Tp __val) { + return __val; +} + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___UTILITY_CONVERT_TO_INTEGRAL_H diff --git a/third_party/libcxx/include/c++/v1/__utility/declval.h b/third_party/libcxx/include/c++/v1/__utility/declval.h new file mode 100644 index 0000000..d0856b8 --- /dev/null +++ b/third_party/libcxx/include/c++/v1/__utility/declval.h @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// 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_DECLVAL_H +#define _LIBCPP___UTILITY_DECLVAL_H + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +// Suppress deprecation notice for volatile-qualified return type resulting +// from volatile-qualified types _Tp. +_LIBCPP_SUPPRESS_DEPRECATED_PUSH +template +_Tp&& __declval(int); +template +_Tp __declval(long); +_LIBCPP_SUPPRESS_DEPRECATED_POP + +template +_LIBCPP_HIDE_FROM_ABI decltype(std::__declval<_Tp>(0)) declval() _NOEXCEPT { + static_assert(!__is_same(_Tp, _Tp), + "std::declval can only be used in an unevaluated context. " + "It's likely that your current usage is trying to extract a value from the function."); +} + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___UTILITY_DECLVAL_H diff --git a/third_party/libcxx/include/c++/v1/__utility/default_three_way_comparator.h b/third_party/libcxx/include/c++/v1/__utility/default_three_way_comparator.h new file mode 100644 index 0000000..92cdce6 --- /dev/null +++ b/third_party/libcxx/include/c++/v1/__utility/default_three_way_comparator.h @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// 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_DEFAULT_THREE_WAY_COMPARATOR_H +#define _LIBCPP___UTILITY_DEFAULT_THREE_WAY_COMPARATOR_H + +#include <__config> +#include <__type_traits/enable_if.h> +#include <__type_traits/is_arithmetic.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +// This struct can be specialized to provide a three way comparator between _LHS and _RHS. +// The return value should be +// - less than zero if (lhs_val < rhs_val) +// - greater than zero if (rhs_val < lhs_val) +// - zero otherwise +template +struct __default_three_way_comparator; + +template +struct __default_three_way_comparator<_LHS, + _RHS, + __enable_if_t::value && is_arithmetic<_RHS>::value> > { + _LIBCPP_HIDE_FROM_ABI static int operator()(_LHS __lhs, _RHS __rhs) { + if (__lhs < __rhs) + return -1; + if (__lhs > __rhs) + return 1; + return 0; + } +}; + +#if _LIBCPP_STD_VER >= 20 && __has_builtin(__builtin_lt_synthesizes_from_spaceship) +template +struct __default_three_way_comparator< + _LHS, + _RHS, + __enable_if_t::value && is_arithmetic<_RHS>::value) && + __builtin_lt_synthesizes_from_spaceship(const _LHS&, const _RHS&)>> { + _LIBCPP_HIDE_FROM_ABI static int operator()(const _LHS& __lhs, const _RHS& __rhs) { + auto __res = __lhs <=> __rhs; + if (__res < 0) + return -1; + if (__res > 0) + return 1; + return 0; + } +}; +#endif + +template +struct __has_default_three_way_comparator : false_type {}; + +template +struct __has_default_three_way_comparator<_LHS, _RHS, sizeof(__default_three_way_comparator<_LHS, _RHS>) >= 0> + : true_type {}; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___UTILITY_DEFAULT_THREE_WAY_COMPARATOR_H diff --git a/third_party/libcxx/include/c++/v1/__utility/element_count.h b/third_party/libcxx/include/c++/v1/__utility/element_count.h new file mode 100644 index 0000000..82b05a7 --- /dev/null +++ b/third_party/libcxx/include/c++/v1/__utility/element_count.h @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// 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_ELEMENT_COUNT_H +#define _LIBCPP___UTILITY_ELEMENT_COUNT_H + +#include <__config> +#include <__cstddef/size_t.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +// Type used to encode that a function takes an integer that represents a number +// of elements as opposed to a number of bytes. +enum class __element_count : size_t {}; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___UTILITY_ELEMENT_COUNT_H diff --git a/third_party/libcxx/include/c++/v1/__utility/empty.h b/third_party/libcxx/include/c++/v1/__utility/empty.h new file mode 100644 index 0000000..8cca197 --- /dev/null +++ b/third_party/libcxx/include/c++/v1/__utility/empty.h @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// 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_EMPTY_H +#define _LIBCPP___UTILITY_EMPTY_H + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +struct __empty {}; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___UTILITY_EMPTY_H diff --git a/third_party/libcxx/include/c++/v1/__utility/exception_guard.h b/third_party/libcxx/include/c++/v1/__utility/exception_guard.h new file mode 100644 index 0000000..6fa744e --- /dev/null +++ b/third_party/libcxx/include/c++/v1/__utility/exception_guard.h @@ -0,0 +1,143 @@ +//===----------------------------------------------------------------------===// +// +// 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_EXCEPTION_GUARD_H +#define _LIBCPP___UTILITY_EXCEPTION_GUARD_H + +#include <__assert> +#include <__config> +#include <__type_traits/is_nothrow_constructible.h> +#include <__utility/move.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +// __exception_guard 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 an +// exception guard so that if an exception is thrown at any point during the lifetime of the +// exception guard, it will be rolled back automatically. When the exception guard is done, one +// must mark it as being complete so it isn't rolled back when the exception guard is destroyed. +// +// Exception guards are not default constructible, they can't be copied or assigned to, but +// they can be moved around for convenience. +// +// __exception_guard is a no-op in -fno-exceptions mode to produce better code-gen. This means +// that we don't provide the strong exception guarantees. However, Clang doesn't generate cleanup +// code with exceptions disabled, so even if we wanted to provide the strong exception guarantees +// we couldn't. This is also only relevant for constructs with a stack of +// -fexceptions > -fno-exceptions > -fexceptions code, since the exception can't be caught where +// exceptions are disabled. While -fexceptions > -fno-exceptions is quite common +// (e.g. libc++.dylib > -fno-exceptions), having another layer with exceptions enabled seems a lot +// less common, especially one that tries to catch an exception through -fno-exceptions code. +// +// __exception_guard can help greatly simplify code that would normally be cluttered by +// `#if _LIBCPP_HAS_EXCEPTIONS`. For example: +// +// template +// Iterator uninitialized_copy_n(Iterator iter, Size n, OutputIterator out) { +// typedef typename iterator_traits::value_type value_type; +// __exception_guard guard([start=out, &out] { +// std::destroy(start, out); +// }); +// +// for (; n > 0; ++iter, ++out, --n) { +// ::new ((void*)std::addressof(*out)) value_type(*iter); +// } +// guard.__complete(); +// return out; +// } +// + +template +struct __exception_guard_exceptions { + __exception_guard_exceptions() = delete; + + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit __exception_guard_exceptions(_Rollback __rollback) + : __rollback_(std::move(__rollback)), __completed_(false) {} + + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 + __exception_guard_exceptions(__exception_guard_exceptions&& __other) + _NOEXCEPT_(is_nothrow_move_constructible<_Rollback>::value) + : __rollback_(std::move(__other.__rollback_)), __completed_(__other.__completed_) { + __other.__completed_ = true; + } + + __exception_guard_exceptions(__exception_guard_exceptions const&) = delete; + __exception_guard_exceptions& operator=(__exception_guard_exceptions const&) = delete; + __exception_guard_exceptions& operator=(__exception_guard_exceptions&&) = delete; + + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __complete() _NOEXCEPT { __completed_ = true; } + + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 ~__exception_guard_exceptions() { + if (!__completed_) + __rollback_(); + } + +private: + _Rollback __rollback_; + bool __completed_; +}; + +_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(__exception_guard_exceptions); + +template +struct __exception_guard_noexceptions { + __exception_guard_noexceptions() = delete; + _LIBCPP_NODEBUG _LIBCPP_HIDE_FROM_ABI + _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit __exception_guard_noexceptions(_Rollback) {} + + _LIBCPP_NODEBUG _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 + __exception_guard_noexceptions(__exception_guard_noexceptions&& __other) + _NOEXCEPT_(is_nothrow_move_constructible<_Rollback>::value) + : __completed_(__other.__completed_) { + __other.__completed_ = true; + } + + __exception_guard_noexceptions(__exception_guard_noexceptions const&) = delete; + __exception_guard_noexceptions& operator=(__exception_guard_noexceptions const&) = delete; + __exception_guard_noexceptions& operator=(__exception_guard_noexceptions&&) = delete; + + _LIBCPP_NODEBUG _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __complete() _NOEXCEPT { + __completed_ = true; + } + + _LIBCPP_NODEBUG _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 ~__exception_guard_noexceptions() { + _LIBCPP_ASSERT_INTERNAL(__completed_, "__exception_guard not completed with exceptions disabled"); + } + +private: + bool __completed_ = false; +}; + +_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(__exception_guard_noexceptions); + +#if !_LIBCPP_HAS_EXCEPTIONS +template +using __exception_guard _LIBCPP_NODEBUG = __exception_guard_noexceptions<_Rollback>; +#else +template +using __exception_guard _LIBCPP_NODEBUG = __exception_guard_exceptions<_Rollback>; +#endif + +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __exception_guard<_Rollback> __make_exception_guard(_Rollback __rollback) { + return __exception_guard<_Rollback>(std::move(__rollback)); +} + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___UTILITY_EXCEPTION_GUARD_H diff --git a/third_party/libcxx/include/c++/v1/__utility/exchange.h b/third_party/libcxx/include/c++/v1/__utility/exchange.h new file mode 100644 index 0000000..957e9d0 --- /dev/null +++ b/third_party/libcxx/include/c++/v1/__utility/exchange.h @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// 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_EXCHANGE_H +#define _LIBCPP___UTILITY_EXCHANGE_H + +#include <__config> +#include <__type_traits/is_nothrow_assignable.h> +#include <__type_traits/is_nothrow_constructible.h> +#include <__utility/forward.h> +#include <__utility/move.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if _LIBCPP_STD_VER >= 14 +template +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _T1 exchange(_T1& __obj, _T2&& __new_value) noexcept( + is_nothrow_move_constructible<_T1>::value && is_nothrow_assignable<_T1&, _T2>::value) { + _T1 __old_value = std::move(__obj); + __obj = std::forward<_T2>(__new_value); + return __old_value; +} +#endif // _LIBCPP_STD_VER >= 14 + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___UTILITY_EXCHANGE_H diff --git a/third_party/libcxx/include/c++/v1/__utility/forward.h b/third_party/libcxx/include/c++/v1/__utility/forward.h new file mode 100644 index 0000000..6674066 --- /dev/null +++ b/third_party/libcxx/include/c++/v1/__utility/forward.h @@ -0,0 +1,38 @@ +// -*- 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___UTILITY_FORWARD_H +#define _LIBCPP___UTILITY_FORWARD_H + +#include <__config> +#include <__type_traits/is_reference.h> +#include <__type_traits/remove_reference.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +template +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp&& +forward(_LIBCPP_LIFETIMEBOUND __libcpp_remove_reference_t<_Tp>& __t) _NOEXCEPT { + return static_cast<_Tp&&>(__t); +} + +template +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp&& +forward(_LIBCPP_LIFETIMEBOUND __libcpp_remove_reference_t<_Tp>&& __t) _NOEXCEPT { + static_assert(!is_lvalue_reference<_Tp>::value, "cannot forward an rvalue as an lvalue"); + return static_cast<_Tp&&>(__t); +} + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___UTILITY_FORWARD_H diff --git a/third_party/libcxx/include/c++/v1/__utility/forward_like.h b/third_party/libcxx/include/c++/v1/__utility/forward_like.h new file mode 100644 index 0000000..409f716 --- /dev/null +++ b/third_party/libcxx/include/c++/v1/__utility/forward_like.h @@ -0,0 +1,63 @@ +// -*- 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___UTILITY_FORWARD_LIKE_H +#define _LIBCPP___UTILITY_FORWARD_LIKE_H + +#include <__config> +#include <__type_traits/conditional.h> +#include <__type_traits/is_base_of.h> +#include <__type_traits/is_const.h> +#include <__type_traits/is_reference.h> +#include <__type_traits/remove_reference.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if _LIBCPP_STD_VER >= 23 + +template +using _CopyConst _LIBCPP_NODEBUG = _If, const _Bp, _Bp>; + +template +using _OverrideRef _LIBCPP_NODEBUG = _If, remove_reference_t<_Bp>&&, _Bp&>; + +template +using _ForwardLike _LIBCPP_NODEBUG = _OverrideRef<_Ap&&, _CopyConst, remove_reference_t<_Bp>>>; + +template +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto +forward_like(_LIBCPP_LIFETIMEBOUND _Up&& __ux) noexcept -> _ForwardLike<_Tp, _Up> { + return static_cast<_ForwardLike<_Tp, _Up>>(__ux); +} + +// This function is used for `deducing this` cases where you want to make sure the operation is performed on the class +// itself and not on a derived class. For example +// struct S { +// template +// void func(Self&& self) { +// // This will always call `do_something` of S instead of any class derived from S. +// std::__forward_as(self).do_something(); +// } +// }; +template +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _ForwardLike<_Tp, _As> +__forward_as(_LIBCPP_LIFETIMEBOUND _Up&& __val) noexcept { + static_assert(is_base_of_v<_As, remove_reference_t<_Up>>); + return static_cast<_ForwardLike<_Tp, _As>>(__val); +} + +#endif // _LIBCPP_STD_VER >= 23 + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___UTILITY_FORWARD_LIKE_H diff --git a/third_party/libcxx/include/c++/v1/__utility/in_place.h b/third_party/libcxx/include/c++/v1/__utility/in_place.h new file mode 100644 index 0000000..c5bfa94 --- /dev/null +++ b/third_party/libcxx/include/c++/v1/__utility/in_place.h @@ -0,0 +1,64 @@ +//===----------------------------------------------------------------------===// +// +// 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_IN_PLACE_H +#define _LIBCPP___UTILITY_IN_PLACE_H + +#include <__config> +#include <__cstddef/size_t.h> +#include <__type_traits/integral_constant.h> +#include <__type_traits/remove_cvref.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if _LIBCPP_STD_VER >= 17 + +struct in_place_t { + explicit in_place_t() = default; +}; +inline constexpr in_place_t in_place{}; + +template +struct in_place_type_t { + _LIBCPP_HIDE_FROM_ABI explicit in_place_type_t() = default; +}; +template +inline constexpr in_place_type_t<_Tp> in_place_type{}; + +template +struct in_place_index_t { + _LIBCPP_HIDE_FROM_ABI explicit in_place_index_t() = default; +}; +template +inline constexpr in_place_index_t<_Idx> in_place_index{}; + +template +struct __is_inplace_type_imp : false_type {}; +template +struct __is_inplace_type_imp> : true_type {}; + +template +using __is_inplace_type _LIBCPP_NODEBUG = __is_inplace_type_imp<__remove_cvref_t<_Tp>>; + +template +struct __is_inplace_index_imp : false_type {}; +template +struct __is_inplace_index_imp> : true_type {}; + +template +using __is_inplace_index _LIBCPP_NODEBUG = __is_inplace_index_imp<__remove_cvref_t<_Tp>>; + +#endif // _LIBCPP_STD_VER >= 17 + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___UTILITY_IN_PLACE_H diff --git a/third_party/libcxx/include/c++/v1/__utility/integer_sequence.h b/third_party/libcxx/include/c++/v1/__utility/integer_sequence.h new file mode 100644 index 0000000..a84f572 --- /dev/null +++ b/third_party/libcxx/include/c++/v1/__utility/integer_sequence.h @@ -0,0 +1,105 @@ +//===----------------------------------------------------------------------===// +// +// 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_INTEGER_SEQUENCE_H +#define _LIBCPP___UTILITY_INTEGER_SEQUENCE_H + +#include <__config> +#include <__cstddef/size_t.h> +#include <__tuple/tuple_element.h> +#include <__tuple/tuple_size.h> +#include <__type_traits/is_integral.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +#ifndef _LIBCPP_CXX03_LANG + +_LIBCPP_BEGIN_NAMESPACE_STD + +# if __has_builtin(__make_integer_seq) +template