summaryrefslogtreecommitdiff
path: root/libstdc++-v3/include/bits/parse_numbers.h
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2020-02-17 14:30:02 +0000
committerJonathan Wakely <jwakely@redhat.com>2020-02-17 15:11:04 +0000
commitc03b53da9129ae2d5ac9629c4b874d0981a7d418 (patch)
treec93017e5e0b7094038b5b8d282aa3e243e557f07 /libstdc++-v3/include/bits/parse_numbers.h
parent4540ef781bcefffe779a8b31950ea737733f06a4 (diff)
downloadgcc-c03b53da9129ae2d5ac9629c4b874d0981a7d418.tar.gz
libstdc++: Add lightweight replacement for std::numeric_limits (PR 92546)
Many uses of std::numeric_limits in C++17 and C++20 features only really need the min(), max() and digits constants for integral types. By adding __detail::__int_limits we can avoid including the whole <limits> header. The <limits> header isn't especially large, but avoiding it still gives small savings in compilation time and memory usage for the compiler. There are also C++11 features that could benefit from this change (e.g. <bits/hashtable_policy.h> and <bits/uniform_int_dist.h>) but I won't change those until stage 1. The implementation of __int_limits assumes two's complement integers, which is true for all targets supported by GCC. PR libstdc++/92546 (partial) * include/Makefile.am: Add new header. * include/Makefile.in: Regenerate. * include/bits/int_limits.h: New header. * include/bits/parse_numbers.h (__select_int::_Select_int): Replace numeric_limits with __detail::__int_limits. * include/std/bit (__rotl, __rotr, __countl_zero, __countl_one) (__countr_zero, __countr_one, __popcount, __ceil2, __floor2, __log2p1): Likewise. * include/std/charconv (__to_chars_8, __from_chars_binary) (__from_chars_alpha_to_num, from_chars): Likewise. * include/std/memory_resource (polymorphic_allocator::allocate) (polymorphic_allocator::allocate_object): Likewise. * include/std/string_view (basic_string_view::_S_compare): Likewise. * include/std/utility (in_range): Likewise. * testsuite/20_util/integer_comparisons/in_range_neg.cc: Adjust for extra error about incomplete type __int_limits<bool>. * testsuite/26_numerics/bit/bit.count/countl_one.cc: Include <limits>. * testsuite/26_numerics/bit/bit.count/countl_zero.cc: Likewise. * testsuite/26_numerics/bit/bit.count/countr_one.cc: Likewise. * testsuite/26_numerics/bit/bit.count/countr_zero.cc: Likewise. * testsuite/26_numerics/bit/bit.count/popcount.cc: Likewise. * testsuite/26_numerics/bit/bit.pow.two/ceil2_neg.cc: Likewise. * testsuite/26_numerics/bit/bit.pow.two/ceil2.cc: Likewise. * testsuite/26_numerics/bit/bit.pow.two/floor2.cc: Likewise. * testsuite/26_numerics/bit/bit.pow.two/ispow2.cc: Likewise. * testsuite/26_numerics/bit/bit.pow.two/log2p1.cc: Likewise. * testsuite/26_numerics/bit/bit.rotate/rotl.cc: Likewise. * testsuite/26_numerics/bit/bit.rotate/rotr.cc: Likewise.
Diffstat (limited to 'libstdc++-v3/include/bits/parse_numbers.h')
-rw-r--r--libstdc++-v3/include/bits/parse_numbers.h8
1 files changed, 4 insertions, 4 deletions
diff --git a/libstdc++-v3/include/bits/parse_numbers.h b/libstdc++-v3/include/bits/parse_numbers.h
index d7a81e55182..6a75d002774 100644
--- a/libstdc++-v3/include/bits/parse_numbers.h
+++ b/libstdc++-v3/include/bits/parse_numbers.h
@@ -34,9 +34,9 @@
// From n3642.pdf except I added binary literals and digit separator '\''.
-#if __cplusplus > 201103L
+#if __cplusplus >= 201402L
-#include <limits>
+#include <bits/int_limits.h>
namespace std _GLIBCXX_VISIBILITY(default)
{
@@ -265,7 +265,7 @@ namespace __select_int
template<unsigned long long _Val, typename _IntType, typename... _Ints>
struct _Select_int_base<_Val, _IntType, _Ints...>
- : conditional_t<(_Val <= std::numeric_limits<_IntType>::max()),
+ : conditional_t<(_Val <= __detail::__int_limits<_IntType>::max()),
integral_constant<_IntType, _Val>,
_Select_int_base<_Val, _Ints...>>
{ };
@@ -289,6 +289,6 @@ namespace __select_int
_GLIBCXX_END_NAMESPACE_VERSION
} // namespace std
-#endif // __cplusplus > 201103L
+#endif // C++14
#endif // _GLIBCXX_PARSE_NUMBERS_H