diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt index ffff8114e5870..23d9aa0adddce 100644 --- a/libcxx/include/CMakeLists.txt +++ b/libcxx/include/CMakeLists.txt @@ -424,6 +424,7 @@ set(files __fwd/format.h __fwd/fstream.h __fwd/functional.h + __fwd/get.h __fwd/ios.h __fwd/istream.h __fwd/mdspan.h @@ -440,6 +441,7 @@ set(files __fwd/string_view.h __fwd/subrange.h __fwd/tuple.h + __fwd/variant.h __fwd/vector.h __hash_table __ios/fpos.h diff --git a/libcxx/include/__fwd/get.h b/libcxx/include/__fwd/get.h new file mode 100644 index 0000000000000..6121ed0efd2ba --- /dev/null +++ b/libcxx/include/__fwd/get.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___FWD_GET_H +#define _LIBCPP___FWD_GET_H + +#include <__config> +#include <__fwd/array.h> +#include <__fwd/complex.h> +#include <__fwd/pair.h> +#include <__fwd/subrange.h> +#include <__fwd/tuple.h> +#include <__fwd/variant.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +#endif // _LIBCPP___FWD_GET_H diff --git a/libcxx/include/__fwd/variant.h b/libcxx/include/__fwd/variant.h new file mode 100644 index 0000000000000..71c792f46a901 --- /dev/null +++ b/libcxx/include/__fwd/variant.h @@ -0,0 +1,77 @@ +//===---------------------------------------------------------------------===// +// +// 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_VARIANT_H +#define _LIBCPP___FWD_VARIANT_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 + +#if _LIBCPP_STD_VER >= 17 + +template +class _LIBCPP_TEMPLATE_VIS variant; + +template +struct _LIBCPP_TEMPLATE_VIS variant_size; + +template +inline constexpr size_t variant_size_v = variant_size<_Tp>::value; + +template +struct _LIBCPP_TEMPLATE_VIS variant_alternative; + +template +using variant_alternative_t = typename variant_alternative<_Ip, _Tp>::type; + +inline constexpr size_t variant_npos = static_cast(-1); + +template +_LIBCPP_HIDE_FROM_ABI +_LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr variant_alternative_t<_Ip, variant<_Types...>>& +get(variant<_Types...>&); + +template +_LIBCPP_HIDE_FROM_ABI +_LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr variant_alternative_t<_Ip, variant<_Types...>>&& +get(variant<_Types...>&&); + +template +_LIBCPP_HIDE_FROM_ABI +_LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr const variant_alternative_t<_Ip, variant<_Types...>>& +get(const variant<_Types...>&); + +template +_LIBCPP_HIDE_FROM_ABI +_LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr const variant_alternative_t<_Ip, variant<_Types...>>&& +get(const variant<_Types...>&&); + +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr _Tp& get(variant<_Types...>&); + +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr _Tp&& get(variant<_Types...>&&); + +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr const _Tp& get(const variant<_Types...>&); + +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr const _Tp&& +get(const variant<_Types...>&&); + +#endif // _LIBCPP_STD_VER >= 17 + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___FWD_VARIANT_H diff --git a/libcxx/include/__ranges/elements_view.h b/libcxx/include/__ranges/elements_view.h index f159f53dc0a83..989d36fbcaaae 100644 --- a/libcxx/include/__ranges/elements_view.h +++ b/libcxx/include/__ranges/elements_view.h @@ -16,7 +16,7 @@ #include <__concepts/derived_from.h> #include <__concepts/equality_comparable.h> #include <__config> -#include <__fwd/complex.h> +#include <__fwd/get.h> #include <__iterator/concepts.h> #include <__iterator/iterator_traits.h> #include <__ranges/access.h> diff --git a/libcxx/include/module.modulemap b/libcxx/include/module.modulemap index add8726dead42..cc419122ed2a6 100644 --- a/libcxx/include/module.modulemap +++ b/libcxx/include/module.modulemap @@ -1813,6 +1813,15 @@ module std_private_tuple_tuple_like_no_subrange [system] { module std_private_tuple_sfinae_helpers [system] { header "__tuple/sfinae_helpers.h" } module std_private_tuple_tuple_element [system] { header "__tuple/tuple_element.h" } module std_private_tuple_tuple_fwd [system] { header "__fwd/tuple.h" } +module std_private_get_fwd [system] { + header "__fwd/get.h" + export std_private_array_array_fwd + export std_private_complex_complex_fwd + export std_private_ranges_subrange_fwd + export std_private_tuple_tuple_fwd + export std_private_utility_pair_fwd + export std_private_variant_fwd +} module std_private_tuple_tuple_indices [system] { header "__tuple/tuple_indices.h" } module std_private_tuple_tuple_like [system] { header "__tuple/tuple_like.h" @@ -2103,5 +2112,6 @@ module std_private_utility_to_underlying [system] { header "__utility/ module std_private_utility_unreachable [system] { header "__utility/unreachable.h" } module std_private_variant_monostate [system] { header "__variant/monostate.h" } +module std_private_variant_fwd [system] { header "__fwd/variant.h" } module std_private_vector_fwd [system] { header "__fwd/vector.h" } diff --git a/libcxx/include/variant b/libcxx/include/variant index 1cac603c27c24..2fa5623d4f118 100644 --- a/libcxx/include/variant +++ b/libcxx/include/variant @@ -221,6 +221,7 @@ namespace std { #include <__functional/invoke.h> #include <__functional/operations.h> #include <__functional/unary_function.h> +#include <__fwd/variant.h> #include <__memory/addressof.h> #include <__memory/construct_at.h> #include <__tuple/find_index.h> @@ -307,15 +308,7 @@ __throw_bad_variant_access() { # endif } -template -class _LIBCPP_TEMPLATE_VIS variant; - -template -struct _LIBCPP_TEMPLATE_VIS variant_size; - -template -inline constexpr size_t variant_size_v = variant_size<_Tp>::value; - +// variant_size template struct _LIBCPP_TEMPLATE_VIS variant_size : variant_size<_Tp> {}; @@ -328,12 +321,7 @@ struct _LIBCPP_TEMPLATE_VIS variant_size : variant_size<_Tp> template struct _LIBCPP_TEMPLATE_VIS variant_size> : integral_constant {}; -template -struct _LIBCPP_TEMPLATE_VIS variant_alternative; - -template -using variant_alternative_t = typename variant_alternative<_Ip, _Tp>::type; - +// variant_alternative template struct _LIBCPP_TEMPLATE_VIS variant_alternative<_Ip, const _Tp> : add_const> {}; @@ -349,8 +337,6 @@ struct _LIBCPP_TEMPLATE_VIS variant_alternative<_Ip, variant<_Types...>> { using type = __type_pack_element<_Ip, _Types...>; }; -inline constexpr size_t variant_npos = static_cast(-1); - template _LIBCPP_HIDE_FROM_ABI constexpr auto __choose_index_type() { # ifdef _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION @@ -369,9 +355,6 @@ using __variant_index_t = decltype(std::__choose_index_type<_NumAlts>()); template constexpr _IndexType __variant_npos = static_cast<_IndexType>(-1); -template -class _LIBCPP_TEMPLATE_VIS variant; - template _LIBCPP_HIDE_FROM_ABI constexpr variant<_Types...>& __as_variant(variant<_Types...>& __vs) noexcept { return __vs;