aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/include/std/array
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2021-11-04 09:31:50 +0000
committerJonathan Wakely <jwakely@redhat.com>2021-11-04 18:14:50 +0000
commit09aab7e699dcbd79fd64959cf259567bdca94022 (patch)
tree7467ae1110fb0c821837196d25106ab817c28c67 /libstdc++-v3/include/std/array
parent1b4a63593bc6b9770789816b205039fdf3cfd3fc (diff)
downloadgcc-09aab7e699dcbd79fd64959cf259567bdca94022.zip
gcc-09aab7e699dcbd79fd64959cf259567bdca94022.tar.gz
gcc-09aab7e699dcbd79fd64959cf259567bdca94022.tar.bz2
libstdc++: Optimize std::tuple_element and std::tuple_size_v
This reduces the number of class template instantiations needed for code using tuples, by reusing _Nth_type in tuple_element and specializing tuple_size_v for tuple, pair and array (and const-qualified versions of them). Also define the _Nth_type primary template as a complete type (but with no nested 'type' member). This avoids "invalid use of incomplete type" errors for out-of-range specializations of tuple_element. Those errors would probably be confusing and unhelpful for users. We already have a user-friendly static assert in tuple_element itself. Also ensure that tuple_size_v is available whenever tuple_size is (as proposed by LWG 3387). We already do that for tuple_element_t. libstdc++-v3/ChangeLog: * include/bits/stl_pair.h (tuple_size_v): Define partial specializations for std::pair. * include/bits/utility.h (_Nth_type): Move definition here and define primary template. (tuple_size_v): Move definition here. * include/std/array (tuple_size_v): Define partial specializations for std::array. * include/std/tuple (tuple_size_v): Move primary template to <bits/utility.h>. Define partial specializations for std::tuple. (tuple_element): Change definition to use _Nth_type. * include/std/variant (_Nth_type): Move to <bits/utility.h>. (variant_alternative, variant): Adjust qualification of _Nth_type. * testsuite/20_util/tuple/element_access/get_neg.cc: Prune additional errors from _Nth_type.
Diffstat (limited to 'libstdc++-v3/include/std/array')
-rw-r--r--libstdc++-v3/include/std/array8
1 files changed, 8 insertions, 0 deletions
diff --git a/libstdc++-v3/include/std/array b/libstdc++-v3/include/std/array
index 3e12d35..413f8e2 100644
--- a/libstdc++-v3/include/std/array
+++ b/libstdc++-v3/include/std/array
@@ -481,6 +481,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
using type = _Tp;
};
+#if __cplusplus >= 201703L
+ template<typename _Tp, size_t _Nm>
+ inline constexpr size_t tuple_size_v<array<_Tp, _Nm>> = _Nm;
+
+ template<typename _Tp, size_t _Nm>
+ inline constexpr size_t tuple_size_v<const array<_Tp, _Nm>> = _Nm;
+#endif
+
template<typename _Tp, size_t _Nm>
struct __is_tuple_like_impl<array<_Tp, _Nm>> : true_type
{ };