]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Add __is_in_place_index_v helper and use it in <variant>
authorJonathan Wakely <jwakely@redhat.com>
Fri, 22 Mar 2024 11:47:44 +0000 (11:47 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Sat, 23 Mar 2024 11:07:57 +0000 (11:07 +0000)
We already have __is_in_place_type_v for in_place_type_t so adding an
equivalent for in_place_index_t allows us avoid a class template
instantiation for the __not_in_place_tag constraint on the most
commonly-used std::variant::variant(T&&) constructor.

For in_place_type_t we also have a __is_in_place_type class template
defined in terms of the variable template, but that isn't actually used
anywhere. I'm not adding an equivalent for the new variable template,
because that wouldn't be used either.

For GCC 15 we should remove the unused __is_in_place_tag and
__is_in_place_type class templates.

libstdc++-v3/ChangeLog:

* include/bits/utility.h (__is_in_place_index_v): New variable
template.
* include/std/variant (__not_in_place_tag): Define in terms of
variable templates not a class template.

libstdc++-v3/include/bits/utility.h
libstdc++-v3/include/std/variant

index 2a741bf700067824ebc631456630443d39444a58..9f3b99231b3c5ed0d3051d1ab0b3ef69bac5239c 100644 (file)
@@ -223,6 +223,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template<typename _Tp>
     using __is_in_place_type = bool_constant<__is_in_place_type_v<_Tp>>;
 
+  template<typename>
+    inline constexpr bool __is_in_place_index_v = false;
+
+  template<size_t _Nm>
+    inline constexpr bool __is_in_place_index_v<in_place_index_t<_Nm>> = true;
+
 #endif // C++17
 
 #if _GLIBCXX_USE_BUILTIN_TRAIT(__type_pack_element)
index 4b9002e0917c90c2976e4524b5030144ddee77f2..f79d95db7a832242c03d869c7e1e73b19c135fa3 100644 (file)
@@ -1414,7 +1414,8 @@ namespace __variant
 
       template<typename _Tp>
        static constexpr bool __not_in_place_tag
-         = !__is_in_place_tag<__remove_cvref_t<_Tp>>::value;
+         = !__is_in_place_type_v<__remove_cvref_t<_Tp>>
+             && !__is_in_place_index_v<__remove_cvref_t<_Tp>>;
 
     public:
 #if __cpp_concepts