From 2d52c6bfae801b016dd3627b8c0e7c4a99405549 Mon Sep 17 00:00:00 2001 From: Nikolas Klauser Date: Mon, 5 Sep 2022 14:38:24 +0200 Subject: [PATCH] [libc++] Granularize __tuple Reviewed By: ldionne, #libc Spies: libcxx-commits, mgorny Differential Revision: https://reviews.llvm.org/D133081 --- libcxx/include/CMakeLists.txt | 12 +- libcxx/include/__functional/hash.h | 2 +- libcxx/include/__fwd/array.h | 26 + libcxx/include/__fwd/get.h | 95 ++++ libcxx/include/__fwd/tuple.h | 29 ++ libcxx/include/__ranges/subrange.h | 4 +- libcxx/include/__tuple | 551 --------------------- libcxx/include/__tuple/apply_cv.h | 70 +++ libcxx/include/__tuple/make_tuple_types.h | 84 ++++ libcxx/include/__tuple/sfinae_helpers.h | 196 ++++++++ libcxx/include/__tuple/tuple_element.h | 93 ++++ libcxx/include/__tuple/tuple_indices.h | 37 ++ libcxx/include/__tuple/tuple_like.h | 44 ++ libcxx/include/__tuple/tuple_size.h | 75 +++ libcxx/include/__tuple/tuple_types.h | 24 + libcxx/include/__utility/integer_sequence.h | 66 +++ libcxx/include/__utility/pair.h | 7 +- libcxx/include/array | 6 +- libcxx/include/experimental/memory_resource | 1 - libcxx/include/module.modulemap.in | 14 +- libcxx/include/optional | 2 +- libcxx/include/ranges | 7 +- libcxx/include/tuple | 2 +- libcxx/include/utility | 7 +- libcxx/include/variant | 1 - libcxx/test/libcxx/private_headers.verify.cpp | 12 +- .../tuple.helper/tuple_element.fail.cpp | 3 +- .../tuple.helper/tuple_size_incomplete.fail.cpp | 6 +- 28 files changed, 907 insertions(+), 569 deletions(-) create mode 100644 libcxx/include/__fwd/array.h create mode 100644 libcxx/include/__fwd/get.h create mode 100644 libcxx/include/__fwd/tuple.h delete mode 100644 libcxx/include/__tuple create mode 100644 libcxx/include/__tuple/apply_cv.h create mode 100644 libcxx/include/__tuple/make_tuple_types.h create mode 100644 libcxx/include/__tuple/sfinae_helpers.h create mode 100644 libcxx/include/__tuple/tuple_element.h create mode 100644 libcxx/include/__tuple/tuple_indices.h create mode 100644 libcxx/include/__tuple/tuple_like.h create mode 100644 libcxx/include/__tuple/tuple_size.h create mode 100644 libcxx/include/__tuple/tuple_types.h diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt index e72b42c..cce8db8 100644 --- a/libcxx/include/CMakeLists.txt +++ b/libcxx/include/CMakeLists.txt @@ -332,10 +332,13 @@ set(files __functional/unary_negate.h __functional/unwrap_ref.h __functional/weak_result_type.h + __fwd/array.h + __fwd/get.h __fwd/hash.h __fwd/pair.h __fwd/span.h __fwd/string_view.h + __fwd/tuple.h __hash_table __ios/fpos.h __iterator/access.h @@ -513,7 +516,14 @@ set(files __thread/timed_backoff_policy.h __threading_support __tree - __tuple + __tuple/apply_cv.h + __tuple/make_tuple_types.h + __tuple/sfinae_helpers.h + __tuple/tuple_element.h + __tuple/tuple_indices.h + __tuple/tuple_like.h + __tuple/tuple_size.h + __tuple/tuple_types.h __type_traits/add_const.h __type_traits/add_cv.h __type_traits/add_lvalue_reference.h diff --git a/libcxx/include/__functional/hash.h b/libcxx/include/__functional/hash.h index 138323f..c121277 100644 --- a/libcxx/include/__functional/hash.h +++ b/libcxx/include/__functional/hash.h @@ -12,7 +12,7 @@ #include <__config> #include <__functional/unary_function.h> #include <__fwd/hash.h> -#include <__tuple> +#include <__tuple/sfinae_helpers.h> #include <__utility/forward.h> #include <__utility/move.h> #include <__utility/pair.h> diff --git a/libcxx/include/__fwd/array.h b/libcxx/include/__fwd/array.h new file mode 100644 index 0000000..9a79eff --- /dev/null +++ b/libcxx/include/__fwd/array.h @@ -0,0 +1,26 @@ +//===---------------------------------------------------------------------===// +// +// 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___FWD_ARRAY_H +#define _LIBCPP___FWD_ARRAY_H + +#include <__config> +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +template +struct _LIBCPP_TEMPLATE_VIS array; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___FWD_ARRAY_H diff --git a/libcxx/include/__fwd/get.h b/libcxx/include/__fwd/get.h new file mode 100644 index 0000000..8162403 --- /dev/null +++ b/libcxx/include/__fwd/get.h @@ -0,0 +1,95 @@ +//===----------------------------------------------------------------------===// +// +// 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___FWD_GET_H +#define _LIBCPP___FWD_GET_H + +#include <__config> +#include <__fwd/array.h> +#include <__fwd/pair.h> +#include <__fwd/tuple.h> +#include <__tuple/tuple_element.h> +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#ifndef _LIBCPP_CXX03_LANG + +template +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 +typename tuple_element<_Ip, tuple<_Tp...> >::type& +get(tuple<_Tp...>&) _NOEXCEPT; + +template +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 +const typename tuple_element<_Ip, tuple<_Tp...> >::type& +get(const tuple<_Tp...>&) _NOEXCEPT; + +template +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 +typename tuple_element<_Ip, tuple<_Tp...> >::type&& +get(tuple<_Tp...>&&) _NOEXCEPT; + +template +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 +const typename tuple_element<_Ip, tuple<_Tp...> >::type&& +get(const tuple<_Tp...>&&) _NOEXCEPT; + +#endif //_LIBCPP_CXX03_LANG + +template +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 +typename tuple_element<_Ip, pair<_T1, _T2> >::type& +get(pair<_T1, _T2>&) _NOEXCEPT; + +template +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 +const typename tuple_element<_Ip, pair<_T1, _T2> >::type& +get(const pair<_T1, _T2>&) _NOEXCEPT; + +#ifndef _LIBCPP_CXX03_LANG +template +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 +typename tuple_element<_Ip, pair<_T1, _T2> >::type&& +get(pair<_T1, _T2>&&) _NOEXCEPT; + +template +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 +const typename tuple_element<_Ip, pair<_T1, _T2> >::type&& +get(const pair<_T1, _T2>&&) _NOEXCEPT; +#endif + +template +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 +_Tp& +get(array<_Tp, _Size>&) _NOEXCEPT; + +template +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 +const _Tp& +get(const array<_Tp, _Size>&) _NOEXCEPT; + +#ifndef _LIBCPP_CXX03_LANG +template +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 +_Tp&& +get(array<_Tp, _Size>&&) _NOEXCEPT; + +template +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 +const _Tp&& +get(const array<_Tp, _Size>&&) _NOEXCEPT; +#endif + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___FWD_GET_H diff --git a/libcxx/include/__fwd/tuple.h b/libcxx/include/__fwd/tuple.h new file mode 100644 index 0000000..16b3fab --- /dev/null +++ b/libcxx/include/__fwd/tuple.h @@ -0,0 +1,29 @@ +//===---------------------------------------------------------------------===// +// +// 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___FWD_TUPLE_H +#define _LIBCPP___FWD_TUPLE_H + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#ifndef _LIBCPP_CXX03_LANG + +template +class _LIBCPP_TEMPLATE_VIS tuple; + +#endif // _LIBCPP_CXX03_LANG + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___FWD_TUPLE_H diff --git a/libcxx/include/__ranges/subrange.h b/libcxx/include/__ranges/subrange.h index 74de775..f8bfddd 100644 --- a/libcxx/include/__ranges/subrange.h +++ b/libcxx/include/__ranges/subrange.h @@ -16,6 +16,7 @@ #include <__concepts/derived_from.h> #include <__concepts/different_from.h> #include <__config> +#include <__fwd/get.h> #include <__iterator/advance.h> #include <__iterator/concepts.h> #include <__iterator/incrementable_traits.h> @@ -26,7 +27,8 @@ #include <__ranges/enable_borrowed_range.h> #include <__ranges/size.h> #include <__ranges/view_interface.h> -#include <__tuple> +#include <__tuple/tuple_element.h> +#include <__tuple/tuple_size.h> #include <__utility/move.h> #include diff --git a/libcxx/include/__tuple b/libcxx/include/__tuple deleted file mode 100644 index abd8e13..0000000 --- a/libcxx/include/__tuple +++ /dev/null @@ -1,551 +0,0 @@ -// -*- 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 -#define _LIBCPP___TUPLE - -#include <__config> -#include <__fwd/pair.h> -#include -#include - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - - -_LIBCPP_BEGIN_NAMESPACE_STD - -template struct _LIBCPP_TEMPLATE_VIS tuple_size; - -#if !defined(_LIBCPP_CXX03_LANG) -template -using __enable_if_tuple_size_imp = _Tp; - -template -struct _LIBCPP_TEMPLATE_VIS tuple_size<__enable_if_tuple_size_imp< - const _Tp, - __enable_if_t::value>, - integral_constant)>>> - : public integral_constant::value> {}; - -template -struct _LIBCPP_TEMPLATE_VIS tuple_size<__enable_if_tuple_size_imp< - volatile _Tp, - __enable_if_t::value>, - integral_constant)>>> - : public integral_constant::value> {}; - -template -struct _LIBCPP_TEMPLATE_VIS tuple_size<__enable_if_tuple_size_imp< - const volatile _Tp, - integral_constant)>>> - : public integral_constant::value> {}; - -#else -template struct _LIBCPP_TEMPLATE_VIS tuple_size : public tuple_size<_Tp> {}; -template struct _LIBCPP_TEMPLATE_VIS tuple_size : public tuple_size<_Tp> {}; -template struct _LIBCPP_TEMPLATE_VIS tuple_size : public tuple_size<_Tp> {}; -#endif - -template struct _LIBCPP_TEMPLATE_VIS tuple_element; - -template -struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, const _Tp> -{ - typedef _LIBCPP_NODEBUG typename add_const::type>::type type; -}; - -template -struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, volatile _Tp> -{ - typedef _LIBCPP_NODEBUG typename add_volatile::type>::type type; -}; - -template -struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, const volatile _Tp> -{ - typedef _LIBCPP_NODEBUG typename add_cv::type>::type type; -}; - -template struct __tuple_like : false_type {}; - -template struct __tuple_like : public __tuple_like<_Tp> {}; -template struct __tuple_like : public __tuple_like<_Tp> {}; -template struct __tuple_like : public __tuple_like<_Tp> {}; - -// tuple specializations - -#ifndef _LIBCPP_CXX03_LANG - -template struct __tuple_indices {}; - -template -struct __integer_sequence { - template