From: Jonathan Wakely Date: Thu, 23 Jun 2022 17:41:17 +0000 (+0100) Subject: libstdc++: Simplify std::variant construction using variable templates X-Git-Tag: basepoints/gcc-14~5920 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=da55353e95f8ace6ff7d48e208e4f216623f6324;p=thirdparty%2Fgcc.git libstdc++: Simplify std::variant construction using variable templates libstdc++-v3/ChangeLog: * include/std/variant (_Build_FUN::_S_fun): Define fallback case as deleted. (__accepted_index, _Extra_visit_slot_needed): Replace class templates with variable templates. --- diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant index c5f25ef6b47..5ff1e3edcdf 100644 --- a/libstdc++-v3/include/std/variant +++ b/libstdc++-v3/include/std/variant @@ -764,7 +764,7 @@ namespace __variant { // This function means 'using _Build_FUN::_S_fun;' is valid, // but only static functions will be considered in the call below. - void _S_fun(); + void _S_fun() = delete; }; // "... for which Ti x[] = {std::forward(t)}; is well-formed." @@ -795,29 +795,28 @@ namespace __variant // The index selected for FUN(std::forward(t)), or variant_npos if none. template - struct __accepted_index - : integral_constant - { }; + inline constexpr size_t + __accepted_index = variant_npos; template - struct __accepted_index<_Tp, _Variant, void_t<_FUN_type<_Tp, _Variant>>> - : _FUN_type<_Tp, _Variant> - { }; + inline constexpr size_t + __accepted_index<_Tp, _Variant, void_t<_FUN_type<_Tp, _Variant>>> + = _FUN_type<_Tp, _Variant>::value; - template - struct _Extra_visit_slot_needed - { - template struct _Variant_never_valueless; + template> + inline constexpr bool + __extra_visit_slot_needed = false; - template - struct _Variant_never_valueless> - : bool_constant<__variant::__never_valueless<_Types...>()> {}; + template + inline constexpr bool + __extra_visit_slot_needed<__variant_cookie, _Var, variant<_Types...>> + = !__variant::__never_valueless<_Types...>(); - static constexpr bool value = - (is_same_v<_Maybe_variant_cookie, __variant_cookie> - || is_same_v<_Maybe_variant_cookie, __variant_idx_cookie>) - && !_Variant_never_valueless<__remove_cvref_t<_Variant>>::value; - }; + template + inline constexpr bool + __extra_visit_slot_needed<__variant_idx_cookie, _Var, variant<_Types...>> + = !__variant::__never_valueless<_Types...>(); // Used for storing a multi-dimensional vtable. template @@ -874,7 +873,7 @@ namespace __variant using _Variant = typename _Nth_type<__index, _Variants...>::type; static constexpr int __do_cookie = - _Extra_visit_slot_needed<_Ret, _Variant>::value ? 1 : 0; + __extra_visit_slot_needed<_Ret, _Variant> ? 1 : 0; using _Tp = _Ret(*)(_Visitor, _Variants...); @@ -953,7 +952,7 @@ namespace __variant _S_apply_all_alts(_Array_type& __vtable, std::index_sequence<__var_indices...>) { - if constexpr (_Extra_visit_slot_needed<_Result_type, _Next>::value) + if constexpr (__extra_visit_slot_needed<_Result_type, _Next>) (_S_apply_single_alt( __vtable._M_arr[__var_indices + 1], &(__vtable._M_arr[0])), ...); @@ -1372,7 +1371,7 @@ namespace __variant template static constexpr size_t __accepted_index - = __detail::__variant::__accepted_index<_Tp, variant>::value; + = __detail::__variant::__accepted_index<_Tp, variant>; template> using __to_type = typename _Nth_type<_Np, _Types...>::type;