Commit 0e1b1222 authored by Jonathan Wakely's avatar Jonathan Wakely
Browse files

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.
parent 953e08fd
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment