]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Optimize compilation time for signed/unsigned integer traits
authorJonathan Wakely <jwakely@redhat.com>
Wed, 10 Dec 2025 14:26:17 +0000 (14:26 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Tue, 16 Dec 2025 22:19:10 +0000 (22:19 +0000)
commit487bd3ba4f1f179be42e3bb13e009d9ff8fc053e
tree165bc6a51f68d0c275e8fd40af068765c7ced0ed
parent7a5ad555965d103e73e606417f4289a4238e82d4
libstdc++: Optimize compilation time for signed/unsigned integer traits

Replace the O(n) definitions using __is_one_of with constant-time
checks that look for a static member in the __is_integral_helper class
template. That class template is already specialized for every signed
and unsigned integer type, so we don't need to define any additional
specializations. We can just add a static data member that says whether
the type is a signed integer type, an unsigned integer type, or neither.
The __is_signed_integer and __is_unsigned_integer traits can then
inspect that value.

The new enum type could be extended in future to distinguish the
character types (char, wchar_t, char8_t, char16_t, and char32_t) and
bool from non-integer types, but that isn't needed for now.

libstdc++-v3/ChangeLog:

* include/std/type_traits (_Integer_kind): New enum type.
(__is_integral_helper::_S_kind): New static data member in
primary template and each explicit specialization.
(__is_signed_integer, __is_unsigned_integer): Use _S_kind
instead of O(n) disjunction with is_same.

Reviewed-by: Patrick Palka <ppalka@redhat.com>
Reviewed-by: Tomasz KamiƄski <tkaminsk@redhat.com>
libstdc++-v3/include/std/type_traits