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/__tuple/find_index.h | 62 ++++++++++++++ third_party/libcxx/include/c++/v1/__tuple/ignore.h | 39 +++++++++ .../libcxx/include/c++/v1/__tuple/sfinae_helpers.h | 99 ++++++++++++++++++++++ .../libcxx/include/c++/v1/__tuple/tuple_element.h | 46 ++++++++++ .../libcxx/include/c++/v1/__tuple/tuple_like.h | 42 +++++++++ .../c++/v1/__tuple/tuple_like_no_subrange.h | 61 +++++++++++++ .../libcxx/include/c++/v1/__tuple/tuple_size.h | 70 +++++++++++++++ .../include/c++/v1/__tuple/tuple_transform.h | 45 ++++++++++ 8 files changed, 464 insertions(+) create mode 100644 third_party/libcxx/include/c++/v1/__tuple/find_index.h create mode 100644 third_party/libcxx/include/c++/v1/__tuple/ignore.h create mode 100644 third_party/libcxx/include/c++/v1/__tuple/sfinae_helpers.h create mode 100644 third_party/libcxx/include/c++/v1/__tuple/tuple_element.h create mode 100644 third_party/libcxx/include/c++/v1/__tuple/tuple_like.h create mode 100644 third_party/libcxx/include/c++/v1/__tuple/tuple_like_no_subrange.h create mode 100644 third_party/libcxx/include/c++/v1/__tuple/tuple_size.h create mode 100644 third_party/libcxx/include/c++/v1/__tuple/tuple_transform.h (limited to 'third_party/libcxx/include/c++/v1/__tuple') diff --git a/third_party/libcxx/include/c++/v1/__tuple/find_index.h b/third_party/libcxx/include/c++/v1/__tuple/find_index.h new file mode 100644 index 0000000..cc7329d --- /dev/null +++ b/third_party/libcxx/include/c++/v1/__tuple/find_index.h @@ -0,0 +1,62 @@ +//===----------------------------------------------------------------------===// +// +// 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___TUPLE_FIND_INDEX_H +#define _LIBCPP___TUPLE_FIND_INDEX_H + +#include <__config> +#include <__cstddef/size_t.h> +#include <__type_traits/is_same.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +#if _LIBCPP_STD_VER >= 14 + +_LIBCPP_BEGIN_NAMESPACE_STD + +namespace __find_detail { + +static constexpr size_t __not_found = static_cast(-1); +static constexpr size_t __ambiguous = __not_found - 1; + +inline _LIBCPP_HIDE_FROM_ABI constexpr size_t __find_idx_return(size_t __curr_i, size_t __res, bool __matches) { + return !__matches ? __res : (__res == __not_found ? __curr_i : __ambiguous); +} + +template +inline _LIBCPP_HIDE_FROM_ABI constexpr size_t __find_idx(size_t __i, const bool (&__matches)[_Nx]) { + return __i == _Nx + ? __not_found + : __find_detail::__find_idx_return(__i, __find_detail::__find_idx(__i + 1, __matches), __matches[__i]); +} + +template +struct __find_exactly_one_checked { + static constexpr bool __matches[sizeof...(_Args)] = {is_same<_T1, _Args>::value...}; + static constexpr size_t value = __find_detail::__find_idx(0, __matches); + static_assert(value != __not_found, "type not found in type list"); + static_assert(value != __ambiguous, "type occurs more than once in type list"); +}; + +template +struct __find_exactly_one_checked<_T1> { + static_assert(!is_same<_T1, _T1>::value, "type not in empty type list"); +}; + +} // namespace __find_detail + +template +struct __find_exactly_one_t : public __find_detail::__find_exactly_one_checked<_T1, _Args...> {}; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_STD_VER >= 14 + +#endif // _LIBCPP___TUPLE_FIND_INDEX_H diff --git a/third_party/libcxx/include/c++/v1/__tuple/ignore.h b/third_party/libcxx/include/c++/v1/__tuple/ignore.h new file mode 100644 index 0000000..43cce53 --- /dev/null +++ b/third_party/libcxx/include/c++/v1/__tuple/ignore.h @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// 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___TUPLE_IGNORE_H +#define _LIBCPP___TUPLE_IGNORE_H + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +#ifndef _LIBCPP_CXX03_LANG + +_LIBCPP_BEGIN_NAMESPACE_STD + +struct __ignore_type { + template + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const __ignore_type& operator=(const _Tp&) const noexcept { + return *this; + } +}; + +# if _LIBCPP_STD_VER >= 17 +inline constexpr __ignore_type ignore; +# else +constexpr __ignore_type ignore; +# endif + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_CXX03_LANG + +#endif // _LIBCPP___TUPLE_IGNORE_H diff --git a/third_party/libcxx/include/c++/v1/__tuple/sfinae_helpers.h b/third_party/libcxx/include/c++/v1/__tuple/sfinae_helpers.h new file mode 100644 index 0000000..f81048f --- /dev/null +++ b/third_party/libcxx/include/c++/v1/__tuple/sfinae_helpers.h @@ -0,0 +1,99 @@ +//===----------------------------------------------------------------------===// +// +// 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___TUPLE_SFINAE_HELPERS_H +#define _LIBCPP___TUPLE_SFINAE_HELPERS_H + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#ifndef _LIBCPP_CXX03_LANG + +struct __check_tuple_constructor_fail { + static _LIBCPP_HIDE_FROM_ABI constexpr bool __enable_explicit_default() { return false; } + static _LIBCPP_HIDE_FROM_ABI constexpr bool __enable_implicit_default() { return false; } + template + static _LIBCPP_HIDE_FROM_ABI constexpr bool __enable_explicit() { + return false; + } + template + static _LIBCPP_HIDE_FROM_ABI constexpr bool __enable_implicit() { + return false; + } + template + static _LIBCPP_HIDE_FROM_ABI constexpr bool __enable_assign() { + return false; + } +}; +#endif // !defined(_LIBCPP_CXX03_LANG) + +#if _LIBCPP_STD_VER >= 17 + +template +struct __sfinae_ctor_base {}; +template <> +struct __sfinae_ctor_base { + __sfinae_ctor_base() = default; + __sfinae_ctor_base(__sfinae_ctor_base const&) = delete; + __sfinae_ctor_base(__sfinae_ctor_base&&) = delete; + __sfinae_ctor_base& operator=(__sfinae_ctor_base const&) = default; + __sfinae_ctor_base& operator=(__sfinae_ctor_base&&) = default; +}; +template <> +struct __sfinae_ctor_base { + __sfinae_ctor_base() = default; + __sfinae_ctor_base(__sfinae_ctor_base const&) = default; + __sfinae_ctor_base(__sfinae_ctor_base&&) = delete; + __sfinae_ctor_base& operator=(__sfinae_ctor_base const&) = default; + __sfinae_ctor_base& operator=(__sfinae_ctor_base&&) = default; +}; +template <> +struct __sfinae_ctor_base { + __sfinae_ctor_base() = default; + __sfinae_ctor_base(__sfinae_ctor_base const&) = delete; + __sfinae_ctor_base(__sfinae_ctor_base&&) = default; + __sfinae_ctor_base& operator=(__sfinae_ctor_base const&) = default; + __sfinae_ctor_base& operator=(__sfinae_ctor_base&&) = default; +}; + +template +struct __sfinae_assign_base {}; +template <> +struct __sfinae_assign_base { + __sfinae_assign_base() = default; + __sfinae_assign_base(__sfinae_assign_base const&) = default; + __sfinae_assign_base(__sfinae_assign_base&&) = default; + __sfinae_assign_base& operator=(__sfinae_assign_base const&) = delete; + __sfinae_assign_base& operator=(__sfinae_assign_base&&) = delete; +}; +template <> +struct __sfinae_assign_base { + __sfinae_assign_base() = default; + __sfinae_assign_base(__sfinae_assign_base const&) = default; + __sfinae_assign_base(__sfinae_assign_base&&) = default; + __sfinae_assign_base& operator=(__sfinae_assign_base const&) = default; + __sfinae_assign_base& operator=(__sfinae_assign_base&&) = delete; +}; +template <> +struct __sfinae_assign_base { + __sfinae_assign_base() = default; + __sfinae_assign_base(__sfinae_assign_base const&) = default; + __sfinae_assign_base(__sfinae_assign_base&&) = default; + __sfinae_assign_base& operator=(__sfinae_assign_base const&) = delete; + __sfinae_assign_base& operator=(__sfinae_assign_base&&) = default; +}; +#endif // _LIBCPP_STD_VER >= 17 + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___TUPLE_SFINAE_HELPERS_H diff --git a/third_party/libcxx/include/c++/v1/__tuple/tuple_element.h b/third_party/libcxx/include/c++/v1/__tuple/tuple_element.h new file mode 100644 index 0000000..50a9807 --- /dev/null +++ b/third_party/libcxx/include/c++/v1/__tuple/tuple_element.h @@ -0,0 +1,46 @@ +//===----------------------------------------------------------------------===// +// +// 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___TUPLE_TUPLE_ELEMENT_H +#define _LIBCPP___TUPLE_TUPLE_ELEMENT_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 + +template +struct tuple_element; + +template +struct tuple_element<_Ip, const _Tp> { + using type _LIBCPP_NODEBUG = const typename tuple_element<_Ip, _Tp>::type; +}; + +template +struct tuple_element<_Ip, volatile _Tp> { + using type _LIBCPP_NODEBUG = volatile typename tuple_element<_Ip, _Tp>::type; +}; + +template +struct tuple_element<_Ip, const volatile _Tp> { + using type _LIBCPP_NODEBUG = const volatile typename tuple_element<_Ip, _Tp>::type; +}; + +# if _LIBCPP_STD_VER >= 14 +template +using tuple_element_t _LIBCPP_NODEBUG = typename tuple_element<_Ip, _Tp...>::type; +# endif + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___TUPLE_TUPLE_ELEMENT_H diff --git a/third_party/libcxx/include/c++/v1/__tuple/tuple_like.h b/third_party/libcxx/include/c++/v1/__tuple/tuple_like.h new file mode 100644 index 0000000..c080a3d --- /dev/null +++ b/third_party/libcxx/include/c++/v1/__tuple/tuple_like.h @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// 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___TUPLE_TUPLE_LIKE_H +#define _LIBCPP___TUPLE_TUPLE_LIKE_H + +#include <__config> +#include <__fwd/subrange.h> +#include <__tuple/tuple_like_no_subrange.h> +#include <__tuple/tuple_size.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 >= 20 + +template +inline constexpr bool __is_ranges_subrange_v = false; + +template +inline constexpr bool __is_ranges_subrange_v> = true; + +template +concept __tuple_like = __tuple_like_no_subrange<_Tp> || __is_ranges_subrange_v>; + +// As of writing this comment every use of `pair-like` in the standard excludes `ranges::subrange`, so +// you most likely want to use `__pair_like_no_subrange` if you're looking for `pair-like`. + +#endif // _LIBCPP_STD_VER >= 20 + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___TUPLE_TUPLE_LIKE_H diff --git a/third_party/libcxx/include/c++/v1/__tuple/tuple_like_no_subrange.h b/third_party/libcxx/include/c++/v1/__tuple/tuple_like_no_subrange.h new file mode 100644 index 0000000..30018d6 --- /dev/null +++ b/third_party/libcxx/include/c++/v1/__tuple/tuple_like_no_subrange.h @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// 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___TUPLE_TUPLE_LIKE_NO_SUBRANGE_H +#define _LIBCPP___TUPLE_TUPLE_LIKE_NO_SUBRANGE_H + +#include <__config> +#include <__cstddef/size_t.h> +#include <__fwd/array.h> +#include <__fwd/complex.h> +#include <__fwd/pair.h> +#include <__fwd/tuple.h> +#include <__tuple/tuple_size.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 >= 20 + +template +inline constexpr bool __tuple_like_no_subrange_impl = false; + +template +inline constexpr bool __tuple_like_no_subrange_impl> = true; + +template +inline constexpr bool __tuple_like_no_subrange_impl> = true; + +template +inline constexpr bool __tuple_like_no_subrange_impl> = true; + +# if _LIBCPP_STD_VER >= 26 + +template +inline constexpr bool __tuple_like_no_subrange_impl> = true; + +# endif + +template +concept __tuple_like_no_subrange = __tuple_like_no_subrange_impl>; + +// This is equivalent to the exposition-only type trait `pair-like`, except that it is false for specializations of +// `ranges::subrange`. This is more useful than the pair-like concept in the standard because every use of `pair-like` +// excludes `ranges::subrange`. +template +concept __pair_like_no_subrange = __tuple_like_no_subrange<_Tp> && tuple_size>::value == 2; + +#endif // _LIBCPP_STD_VER >= 20 + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___TUPLE_TUPLE_LIKE_NO_SUBRANGE_H diff --git a/third_party/libcxx/include/c++/v1/__tuple/tuple_size.h b/third_party/libcxx/include/c++/v1/__tuple/tuple_size.h new file mode 100644 index 0000000..719edc0 --- /dev/null +++ b/third_party/libcxx/include/c++/v1/__tuple/tuple_size.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___TUPLE_TUPLE_SIZE_H +#define _LIBCPP___TUPLE_TUPLE_SIZE_H + +#include <__config> +#include <__cstddef/size_t.h> +#include <__fwd/tuple.h> +#include <__type_traits/enable_if.h> +#include <__type_traits/integral_constant.h> +#include <__type_traits/is_const.h> +#include <__type_traits/is_volatile.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +template +struct tuple_size; + +#if !defined(_LIBCPP_CXX03_LANG) +template +using __enable_if_tuple_size_imp _LIBCPP_NODEBUG = _Tp; + +template +struct tuple_size< + __enable_if_tuple_size_imp::value>, decltype(tuple_size<_Tp>::value)>> + : public integral_constant::value> {}; + +template +struct tuple_size< + __enable_if_tuple_size_imp::value>, decltype(tuple_size<_Tp>::value)>> + : public integral_constant::value> {}; + +template +struct tuple_size<__enable_if_tuple_size_imp::value)>> + : public integral_constant::value> {}; + +#else +template +struct tuple_size : public tuple_size<_Tp> {}; +template +struct tuple_size : public tuple_size<_Tp> {}; +template +struct tuple_size : public tuple_size<_Tp> {}; +#endif + +#ifndef _LIBCPP_CXX03_LANG + +template +struct tuple_size > : public integral_constant {}; + +# if _LIBCPP_STD_VER >= 17 +template +inline constexpr size_t tuple_size_v = tuple_size<_Tp>::value; +# endif + +#endif // _LIBCPP_CXX03_LANG + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___TUPLE_TUPLE_SIZE_H diff --git a/third_party/libcxx/include/c++/v1/__tuple/tuple_transform.h b/third_party/libcxx/include/c++/v1/__tuple/tuple_transform.h new file mode 100644 index 0000000..92a18e0 --- /dev/null +++ b/third_party/libcxx/include/c++/v1/__tuple/tuple_transform.h @@ -0,0 +1,45 @@ +// -*- 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___TUPLE_TUPLE_TRANSFORM_H +#define _LIBCPP___TUPLE_TUPLE_TRANSFORM_H + +#include <__config> + +#include <__functional/invoke.h> +#include <__utility/forward.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 >= 23 + +template +_LIBCPP_HIDE_FROM_ABI constexpr auto __tuple_transform(_Fun&& __f, _Tuple&& __tuple) { + return std::apply( + [&](_Types&&... __elements) { + return tuple...>(std::invoke(__f, std::forward<_Types>(__elements))...); + }, + std::forward<_Tuple>(__tuple)); +} + +#endif // _LIBCPP_STD_VER >= 23 + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___TUPLE_TUPLE_TRANSFORM_H -- cgit v1.2.3