2013-06-01 18:37:47 +00:00
|
|
|
// Components for compile-time parsing of numbers -*- C++ -*-
|
|
|
|
|
|
2026-01-02 09:53:48 +01:00
|
|
|
// Copyright (C) 2013-2026 Free Software Foundation, Inc.
|
2013-06-01 18:37:47 +00:00
|
|
|
//
|
|
|
|
|
// This file is part of the GNU ISO C++ Library. This library is free
|
|
|
|
|
// software; you can redistribute it and/or modify it under the
|
|
|
|
|
// terms of the GNU General Public License as published by the
|
|
|
|
|
// Free Software Foundation; either version 3, or (at your option)
|
|
|
|
|
// any later version.
|
|
|
|
|
|
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
// Under Section 7 of GPL version 3, you are granted additional
|
|
|
|
|
// permissions described in the GCC Runtime Library Exception, version
|
|
|
|
|
// 3.1, as published by the Free Software Foundation.
|
|
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License and
|
|
|
|
|
// a copy of the GCC Runtime Library Exception along with this program;
|
|
|
|
|
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
|
|
|
|
|
// <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
/** @file bits/parse_numbers.h
|
|
|
|
|
* This is an internal header file, included by other library headers.
|
|
|
|
|
* Do not attempt to use it directly. @headername{chrono}
|
|
|
|
|
*/
|
|
|
|
|
|
2014-05-16 09:30:57 +00:00
|
|
|
#ifndef _GLIBCXX_PARSE_NUMBERS_H
|
|
|
|
|
#define _GLIBCXX_PARSE_NUMBERS_H 1
|
2013-06-01 18:37:47 +00:00
|
|
|
|
2024-09-12 12:15:51 -04:00
|
|
|
#ifdef _GLIBCXX_SYSHDR
|
2013-06-01 18:37:47 +00:00
|
|
|
#pragma GCC system_header
|
2024-09-12 12:15:51 -04:00
|
|
|
#endif
|
2013-06-01 18:37:47 +00:00
|
|
|
|
2013-10-31 14:01:23 +00:00
|
|
|
// From n3642.pdf except I added binary literals and digit separator '\''.
|
2013-06-01 18:37:47 +00:00
|
|
|
|
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.
2020-02-17 14:30:02 +00:00
|
|
|
#if __cplusplus >= 201402L
|
2013-06-01 18:37:47 +00:00
|
|
|
|
2021-03-10 15:27:41 +00:00
|
|
|
#include <type_traits>
|
libstdc++: Replace __int_limits with __numeric_traits_integer
I recently added std::__detail::__int_limits as a lightweight
alternative to std::numeric_limits, forgetting that the values it
provides (digits, min and max) are already provided by
__gnu_cxx::__numeric_traits.
This change adds __int_traits as an alias for __numeric_traits_integer.
This avoids instantiating __numeric_traits to decide whether to use
__numeric_traits_integer or __numeric_traits_floating. Then all uses of
__int_limits can be replaced with __int_traits, and __int_limits can be
removed.
libstdc++-v3/ChangeLog:
* include/Makefile.am: Remove bits/int_limits.h.
* include/Makefile.in: Regenerate.
* include/bits/int_limits.h: Removed.
* include/bits/parse_numbers.h (_Select_int_base): Replace
__int_limits with __int_traits.
* include/bits/range_access.h (_SSize::operator()): Likewise.
* include/ext/numeric_traits.h (__numeric_traits_integer): Add
static assertion.
(__int_traits): New alias template.
* include/std/bit (__rotl, __rotr, __countl_zero, __countl_one)
(__countr_zero, __countr_one, __popcount, __bit_ceil)
(__bit_floor, __bit_width) Replace __int_limits with
__int_traits.
* 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 (cmp_equal, cmp_less, in_range): Likewise.
2020-07-07 23:26:38 +01:00
|
|
|
#include <ext/numeric_traits.h>
|
2014-05-16 09:30:57 +00:00
|
|
|
|
2013-06-01 18:37:47 +00:00
|
|
|
namespace std _GLIBCXX_VISIBILITY(default)
|
|
|
|
|
{
|
|
|
|
|
_GLIBCXX_BEGIN_NAMESPACE_VERSION
|
|
|
|
|
|
2014-05-16 09:30:57 +00:00
|
|
|
namespace __parse_int
|
|
|
|
|
{
|
2013-06-01 18:37:47 +00:00
|
|
|
template<unsigned _Base, char _Dig>
|
|
|
|
|
struct _Digit;
|
|
|
|
|
|
|
|
|
|
template<unsigned _Base>
|
2014-05-16 09:30:57 +00:00
|
|
|
struct _Digit<_Base, '0'> : integral_constant<unsigned, 0>
|
2013-06-01 18:37:47 +00:00
|
|
|
{
|
2014-05-16 09:30:57 +00:00
|
|
|
using __valid = true_type;
|
2013-06-01 18:37:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<unsigned _Base>
|
2014-05-16 09:30:57 +00:00
|
|
|
struct _Digit<_Base, '1'> : integral_constant<unsigned, 1>
|
2013-06-01 18:37:47 +00:00
|
|
|
{
|
2014-05-16 09:30:57 +00:00
|
|
|
using __valid = true_type;
|
2013-06-01 18:37:47 +00:00
|
|
|
};
|
|
|
|
|
|
2014-05-16 09:30:57 +00:00
|
|
|
template<unsigned _Base, unsigned _Val>
|
|
|
|
|
struct _Digit_impl : integral_constant<unsigned, _Val>
|
2013-06-01 18:37:47 +00:00
|
|
|
{
|
2014-05-16 09:30:57 +00:00
|
|
|
static_assert(_Base > _Val, "invalid digit");
|
|
|
|
|
using __valid = true_type;
|
2013-06-01 18:37:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<unsigned _Base>
|
2014-05-16 09:30:57 +00:00
|
|
|
struct _Digit<_Base, '2'> : _Digit_impl<_Base, 2>
|
|
|
|
|
{ };
|
2013-06-01 18:37:47 +00:00
|
|
|
|
|
|
|
|
template<unsigned _Base>
|
2014-05-16 09:30:57 +00:00
|
|
|
struct _Digit<_Base, '3'> : _Digit_impl<_Base, 3>
|
|
|
|
|
{ };
|
2013-06-01 18:37:47 +00:00
|
|
|
|
|
|
|
|
template<unsigned _Base>
|
2014-05-16 09:30:57 +00:00
|
|
|
struct _Digit<_Base, '4'> : _Digit_impl<_Base, 4>
|
|
|
|
|
{ };
|
2013-06-01 18:37:47 +00:00
|
|
|
|
|
|
|
|
template<unsigned _Base>
|
2014-05-16 09:30:57 +00:00
|
|
|
struct _Digit<_Base, '5'> : _Digit_impl<_Base, 5>
|
|
|
|
|
{ };
|
2013-06-01 18:37:47 +00:00
|
|
|
|
|
|
|
|
template<unsigned _Base>
|
2014-05-16 09:30:57 +00:00
|
|
|
struct _Digit<_Base, '6'> : _Digit_impl<_Base, 6>
|
|
|
|
|
{ };
|
2013-06-01 18:37:47 +00:00
|
|
|
|
|
|
|
|
template<unsigned _Base>
|
2014-05-16 09:30:57 +00:00
|
|
|
struct _Digit<_Base, '7'> : _Digit_impl<_Base, 7>
|
|
|
|
|
{ };
|
2013-06-01 18:37:47 +00:00
|
|
|
|
|
|
|
|
template<unsigned _Base>
|
2014-05-16 09:30:57 +00:00
|
|
|
struct _Digit<_Base, '8'> : _Digit_impl<_Base, 8>
|
|
|
|
|
{ };
|
2013-06-01 18:37:47 +00:00
|
|
|
|
|
|
|
|
template<unsigned _Base>
|
2014-05-16 09:30:57 +00:00
|
|
|
struct _Digit<_Base, '9'> : _Digit_impl<_Base, 9>
|
|
|
|
|
{ };
|
2013-06-01 18:37:47 +00:00
|
|
|
|
|
|
|
|
template<unsigned _Base>
|
2014-05-16 09:30:57 +00:00
|
|
|
struct _Digit<_Base, 'a'> : _Digit_impl<_Base, 0xa>
|
|
|
|
|
{ };
|
2013-06-01 18:37:47 +00:00
|
|
|
|
|
|
|
|
template<unsigned _Base>
|
2014-05-16 09:30:57 +00:00
|
|
|
struct _Digit<_Base, 'A'> : _Digit_impl<_Base, 0xa>
|
|
|
|
|
{ };
|
2013-06-01 18:37:47 +00:00
|
|
|
|
|
|
|
|
template<unsigned _Base>
|
2014-05-16 09:30:57 +00:00
|
|
|
struct _Digit<_Base, 'b'> : _Digit_impl<_Base, 0xb>
|
|
|
|
|
{ };
|
2013-06-01 18:37:47 +00:00
|
|
|
|
|
|
|
|
template<unsigned _Base>
|
2014-05-16 09:30:57 +00:00
|
|
|
struct _Digit<_Base, 'B'> : _Digit_impl<_Base, 0xb>
|
|
|
|
|
{ };
|
2013-06-01 18:37:47 +00:00
|
|
|
|
|
|
|
|
template<unsigned _Base>
|
2014-05-16 09:30:57 +00:00
|
|
|
struct _Digit<_Base, 'c'> : _Digit_impl<_Base, 0xc>
|
|
|
|
|
{ };
|
2013-06-01 18:37:47 +00:00
|
|
|
|
|
|
|
|
template<unsigned _Base>
|
2014-05-16 09:30:57 +00:00
|
|
|
struct _Digit<_Base, 'C'> : _Digit_impl<_Base, 0xc>
|
|
|
|
|
{ };
|
2013-06-01 18:37:47 +00:00
|
|
|
|
|
|
|
|
template<unsigned _Base>
|
2014-05-16 09:30:57 +00:00
|
|
|
struct _Digit<_Base, 'd'> : _Digit_impl<_Base, 0xd>
|
|
|
|
|
{ };
|
2013-06-01 18:37:47 +00:00
|
|
|
|
|
|
|
|
template<unsigned _Base>
|
2014-05-16 09:30:57 +00:00
|
|
|
struct _Digit<_Base, 'D'> : _Digit_impl<_Base, 0xd>
|
|
|
|
|
{ };
|
2013-06-01 18:37:47 +00:00
|
|
|
|
|
|
|
|
template<unsigned _Base>
|
2014-05-16 09:30:57 +00:00
|
|
|
struct _Digit<_Base, 'e'> : _Digit_impl<_Base, 0xe>
|
|
|
|
|
{ };
|
2013-06-01 18:37:47 +00:00
|
|
|
|
|
|
|
|
template<unsigned _Base>
|
2014-05-16 09:30:57 +00:00
|
|
|
struct _Digit<_Base, 'E'> : _Digit_impl<_Base, 0xe>
|
|
|
|
|
{ };
|
2013-06-01 18:37:47 +00:00
|
|
|
|
|
|
|
|
template<unsigned _Base>
|
2014-05-16 09:30:57 +00:00
|
|
|
struct _Digit<_Base, 'f'> : _Digit_impl<_Base, 0xf>
|
|
|
|
|
{ };
|
2013-06-01 18:37:47 +00:00
|
|
|
|
|
|
|
|
template<unsigned _Base>
|
2014-05-16 09:30:57 +00:00
|
|
|
struct _Digit<_Base, 'F'> : _Digit_impl<_Base, 0xf>
|
|
|
|
|
{ };
|
2013-06-01 18:37:47 +00:00
|
|
|
|
2014-05-16 09:30:57 +00:00
|
|
|
// Digit separator
|
2013-06-01 18:37:47 +00:00
|
|
|
template<unsigned _Base>
|
2014-05-16 09:30:57 +00:00
|
|
|
struct _Digit<_Base, '\''> : integral_constant<unsigned, 0>
|
2013-06-01 18:37:47 +00:00
|
|
|
{
|
2014-05-16 09:30:57 +00:00
|
|
|
using __valid = false_type;
|
2013-06-01 18:37:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
2014-05-16 09:30:57 +00:00
|
|
|
template<unsigned long long _Val>
|
|
|
|
|
using __ull_constant = integral_constant<unsigned long long, _Val>;
|
|
|
|
|
|
2013-06-01 18:37:47 +00:00
|
|
|
template<unsigned _Base, char _Dig, char... _Digs>
|
|
|
|
|
struct _Power_help
|
|
|
|
|
{
|
2014-05-16 09:30:57 +00:00
|
|
|
using __next = typename _Power_help<_Base, _Digs...>::type;
|
|
|
|
|
using __valid_digit = typename _Digit<_Base, _Dig>::__valid;
|
|
|
|
|
using type
|
|
|
|
|
= __ull_constant<__next::value * (__valid_digit{} ? _Base : 1ULL)>;
|
2013-06-01 18:37:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<unsigned _Base, char _Dig>
|
|
|
|
|
struct _Power_help<_Base, _Dig>
|
|
|
|
|
{
|
2014-05-16 09:30:57 +00:00
|
|
|
using __valid_digit = typename _Digit<_Base, _Dig>::__valid;
|
|
|
|
|
using type = __ull_constant<__valid_digit::value>;
|
2013-06-01 18:37:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<unsigned _Base, char... _Digs>
|
2014-05-16 09:30:57 +00:00
|
|
|
struct _Power : _Power_help<_Base, _Digs...>::type
|
|
|
|
|
{ };
|
2013-06-01 18:37:47 +00:00
|
|
|
|
|
|
|
|
template<unsigned _Base>
|
2014-05-16 09:30:57 +00:00
|
|
|
struct _Power<_Base> : __ull_constant<0>
|
|
|
|
|
{ };
|
2013-06-01 18:37:47 +00:00
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
2014-05-16 09:30:57 +00:00
|
|
|
template<unsigned _Base, unsigned long long _Pow, char _Dig, char... _Digs>
|
2013-06-01 18:37:47 +00:00
|
|
|
struct _Number_help
|
|
|
|
|
{
|
2014-05-16 09:30:57 +00:00
|
|
|
using __digit = _Digit<_Base, _Dig>;
|
|
|
|
|
using __valid_digit = typename __digit::__valid;
|
|
|
|
|
using __next = _Number_help<_Base,
|
2014-06-23 12:30:32 +01:00
|
|
|
__valid_digit::value ? _Pow / _Base : _Pow,
|
2014-05-16 09:30:57 +00:00
|
|
|
_Digs...>;
|
|
|
|
|
using type = __ull_constant<_Pow * __digit::value + __next::type::value>;
|
2014-06-23 12:30:32 +01:00
|
|
|
static_assert((type::value / _Pow) == __digit::value,
|
|
|
|
|
"integer literal does not fit in unsigned long long");
|
2013-06-01 18:37:47 +00:00
|
|
|
};
|
|
|
|
|
|
2018-03-02 20:38:50 +00:00
|
|
|
// Skip past digit separators:
|
|
|
|
|
template<unsigned _Base, unsigned long long _Pow, char _Dig, char..._Digs>
|
|
|
|
|
struct _Number_help<_Base, _Pow, '\'', _Dig, _Digs...>
|
|
|
|
|
: _Number_help<_Base, _Pow, _Dig, _Digs...>
|
|
|
|
|
{ };
|
|
|
|
|
|
|
|
|
|
// Terminating case for recursion:
|
|
|
|
|
template<unsigned _Base, char _Dig>
|
|
|
|
|
struct _Number_help<_Base, 1ULL, _Dig>
|
2013-06-01 18:37:47 +00:00
|
|
|
{
|
2014-05-16 09:30:57 +00:00
|
|
|
using type = __ull_constant<_Digit<_Base, _Dig>::value>;
|
2013-06-01 18:37:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<unsigned _Base, char... _Digs>
|
|
|
|
|
struct _Number
|
2014-05-16 09:30:57 +00:00
|
|
|
: _Number_help<_Base, _Power<_Base, _Digs...>::value, _Digs...>::type
|
|
|
|
|
{ };
|
2013-06-01 18:37:47 +00:00
|
|
|
|
|
|
|
|
template<unsigned _Base>
|
|
|
|
|
struct _Number<_Base>
|
2014-05-16 09:30:57 +00:00
|
|
|
: __ull_constant<0>
|
|
|
|
|
{ };
|
2013-06-01 18:37:47 +00:00
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
template<char... _Digs>
|
|
|
|
|
struct _Parse_int;
|
|
|
|
|
|
|
|
|
|
template<char... _Digs>
|
|
|
|
|
struct _Parse_int<'0', 'b', _Digs...>
|
2014-05-16 09:30:57 +00:00
|
|
|
: _Number<2U, _Digs...>::type
|
|
|
|
|
{ };
|
2013-06-01 18:37:47 +00:00
|
|
|
|
|
|
|
|
template<char... _Digs>
|
|
|
|
|
struct _Parse_int<'0', 'B', _Digs...>
|
2014-05-16 09:30:57 +00:00
|
|
|
: _Number<2U, _Digs...>::type
|
|
|
|
|
{ };
|
2013-06-01 18:37:47 +00:00
|
|
|
|
|
|
|
|
template<char... _Digs>
|
|
|
|
|
struct _Parse_int<'0', 'x', _Digs...>
|
2014-05-16 09:30:57 +00:00
|
|
|
: _Number<16U, _Digs...>::type
|
|
|
|
|
{ };
|
2013-06-01 18:37:47 +00:00
|
|
|
|
|
|
|
|
template<char... _Digs>
|
|
|
|
|
struct _Parse_int<'0', 'X', _Digs...>
|
2014-05-16 09:30:57 +00:00
|
|
|
: _Number<16U, _Digs...>::type
|
|
|
|
|
{ };
|
2013-06-01 18:37:47 +00:00
|
|
|
|
|
|
|
|
template<char... _Digs>
|
|
|
|
|
struct _Parse_int<'0', _Digs...>
|
2014-05-16 09:30:57 +00:00
|
|
|
: _Number<8U, _Digs...>::type
|
|
|
|
|
{ };
|
2013-06-01 18:37:47 +00:00
|
|
|
|
|
|
|
|
template<char... _Digs>
|
|
|
|
|
struct _Parse_int
|
2014-05-16 09:30:57 +00:00
|
|
|
: _Number<10U, _Digs...>::type
|
|
|
|
|
{ };
|
2013-06-01 18:37:47 +00:00
|
|
|
|
|
|
|
|
} // namespace __parse_int
|
|
|
|
|
|
|
|
|
|
|
2014-05-16 09:30:57 +00:00
|
|
|
namespace __select_int
|
|
|
|
|
{
|
2013-06-01 18:37:47 +00:00
|
|
|
template<unsigned long long _Val, typename... _Ints>
|
|
|
|
|
struct _Select_int_base;
|
|
|
|
|
|
|
|
|
|
template<unsigned long long _Val, typename _IntType, typename... _Ints>
|
|
|
|
|
struct _Select_int_base<_Val, _IntType, _Ints...>
|
libstdc++: Add std::__conditional_t alias template
This change is inspired by the suggestion in
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1715r0.html
The new std::__conditional_t alias template is functionally equivalent
to std::conditional_t but should be more efficient to compile, due to
only ever instantiating two specializations (std::__conditional<true>
and std::__conditional<false>) rather than a new specialization for
every use of std::conditional.
The new alias template is also available in C++11, unlike the C++14
std::conditional_t alias.
Signed-off-by: Jonathan Wakely <jwakely@redhat.com>
libstdc++-v3/ChangeLog:
* include/std/type_traits (__conditional): New class template
for internal uses of std::conditional.
(__conditional_t): New alias template to replace conditional_t.
(__and_, __or_, __result_of_memfun, __result_of_memobj): Use
__conditional_t instead of conditional::type.
* include/bits/atomic_base.h (__atomic_impl::_Diff): Likewise.
* include/bits/hashtable.h (_Hashtable): Likewise.
* include/bits/hashtable_policy.h (_Node_iterator, _Insert_base)
(_Local_iterator): Likewise. Replace typedefs with
using-declarations.
* include/bits/move.h (move_if_noexcept): Use __conditional_t.
* include/bits/parse_numbers.h (_Select_int_base): Likewise.
* include/bits/ptr_traits.h (__make_not_void): Likewise.
* include/bits/ranges_algobase.h (__copy_or_move_backward)
(__copy_or_move): Likewise.
* include/bits/ranges_base.h (borrowed_iterator_t): Likewise.
* include/bits/ranges_util.h (borrowed_subrange_t): Likewise.
* include/bits/regex_compiler.h (_BracketMatcher): Use
__conditional_t. Replace typedefs with using-declarations.
* include/bits/shared_ptr_base.h (__shared_count): Use
__conditional_t.
* include/bits/stl_algobase.h (__copy_move, __copy_move_backward):
Likewise.
* include/bits/stl_iterator.h (__detail::__clamp_iter_cat)
(reverse_iterator::iterator_concept)
(__make_move_if_noexcept_iterator)
(iterator_traits<common_iterator<_It, _Sent>>)
(iterator_traits<counted_iterator<_It>>): Likewise.
* include/bits/stl_pair.h (_PCC, pair::operator=): Likewise.
* include/bits/stl_tree.h (_Rb_tree::insert_return_type)
(_Rb_tree::_M_clone_node): Likewise.
* include/bits/unique_ptr.h (unique_ptr(unique_ptr<U,E>&&)):
Likewise.
* include/bits/uses_allocator.h (__uses_alloc): Likewise.
(__is_uses_allocator_predicate): Likewise.
* include/debug/functions.h (__foreign_iterator_aux2): Likewise.
* include/experimental/any (any::_Manager, __any_caster):
Likewise.
* include/experimental/executor (async_completion): Likewise.
* include/experimental/functional (__boyer_moore_base_t):
Likewise.
* include/std/any (any::_Manager): Likewise.
* include/std/functional (__boyer_moore_base_t): Likewise.
* include/std/ranges (borrowed_iterator_t)
(borrowed_subrange_t, __detail::__maybe_present_t)
(__detail::__maybe_const_t, split_view): Likewise.
* include/std/tuple (__empty_not_final, tuple::operator=):
Likewise.
* include/std/variant (__detail::__variant::__get_t): Likewise.
2021-05-06 16:26:21 +01:00
|
|
|
: __conditional_t<(_Val <= __gnu_cxx::__int_traits<_IntType>::__max),
|
|
|
|
|
integral_constant<_IntType, (_IntType)_Val>,
|
|
|
|
|
_Select_int_base<_Val, _Ints...>>
|
2013-06-01 18:37:47 +00:00
|
|
|
{ };
|
|
|
|
|
|
|
|
|
|
template<unsigned long long _Val>
|
2014-05-16 09:30:57 +00:00
|
|
|
struct _Select_int_base<_Val>
|
2013-06-01 18:37:47 +00:00
|
|
|
{ };
|
|
|
|
|
|
|
|
|
|
template<char... _Digs>
|
2014-05-16 09:30:57 +00:00
|
|
|
using _Select_int = typename _Select_int_base<
|
2013-06-01 18:37:47 +00:00
|
|
|
__parse_int::_Parse_int<_Digs...>::value,
|
|
|
|
|
unsigned char,
|
|
|
|
|
unsigned short,
|
|
|
|
|
unsigned int,
|
|
|
|
|
unsigned long,
|
|
|
|
|
unsigned long long
|
2014-05-16 09:30:57 +00:00
|
|
|
>::type;
|
2013-06-01 18:37:47 +00:00
|
|
|
|
|
|
|
|
} // namespace __select_int
|
|
|
|
|
|
|
|
|
|
_GLIBCXX_END_NAMESPACE_VERSION
|
|
|
|
|
} // namespace std
|
|
|
|
|
|
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.
2020-02-17 14:30:02 +00:00
|
|
|
#endif // C++14
|
2013-06-01 18:37:47 +00:00
|
|
|
|
2014-05-16 09:30:57 +00:00
|
|
|
#endif // _GLIBCXX_PARSE_NUMBERS_H
|