]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Optimize array traits
authorJonathan Wakely <jwakely@redhat.com>
Wed, 31 Aug 2022 14:00:07 +0000 (15:00 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Thu, 1 Sep 2022 09:22:07 +0000 (10:22 +0100)
commit0e1b1222af5e5346df9431df817f2e7dca01bee6
tree7457f84773265393ceeacfe8ba85473e7c5f6422
parent953e08fde44a596e4ec2491efd15cd645e1ddc48
libstdc++: Optimize array traits

Improve compile times by avoiding unnecessary class template
instantiations.

__is_array_known_bounds and __is_array_unknown_bounds can be defined
without instantiating extent, by providing partial specializations for
the true cases.

std::extent can avoid recursing down through a multidimensional array,
so it stops after providing the result. Previously extent<T[n][m], 0>
would instantiate extent<T[n], -1u> and extent<T, -2u> as well.

std::is_array_v can use partial specializations to avoid instantiating
std::is_array, and similarly for std::rank_v and std::extent_v.

std::is_bounded_array_v and std::is_unbounded_array_v can also use
partial specializations, and then the class templates can be defined in
terms of the variable templates. This makes sense for these traits,
because they are new in C++20 and so the variable templates are always
available, which isn't true in general for C++11 and C++14 traits.

libstdc++-v3/ChangeLog:

* include/std/type_traits (__is_array_known_bounds): Add partial
specialization instead of using std::extent.
(__is_array_unknown_bounds): Likewise.
(extent): Add partial specializations to stop recursion after
the result is found.
(is_array_v): Add partial specializations instead of
instantiating the class template.
(rank_v, extent_v): Likewise.
(is_bounded_array_v, is_unbounded_array_v): Likewise.
(is_bounded_array, is_unbounded_array): Define in terms of the
variable templates.
libstdc++-v3/include/std/type_traits