| 1 |
// Copyright (C) 2020-2025 Free Software Foundation, Inc. |
| 2 |
// |
| 3 |
// This file is part of the GNU ISO C++ Library. This library is free |
| 4 |
// software; you can redistribute it and/or modify it under the |
| 5 |
// terms of the GNU General Public License as published by the |
| 6 |
// Free Software Foundation; either version 3, or (at your option) |
| 7 |
// any later version. |
| 8 |
|
| 9 |
// This library is distributed in the hope that it will be useful, |
| 10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
// GNU General Public License for more details. |
| 13 |
|
| 14 |
// You should have received a copy of the GNU General Public License along |
| 15 |
// with this library; see the file COPYING3. If not see |
| 16 |
// <http://www.gnu.org/licenses/>. |
| 17 |
|
| 18 |
// { dg-do compile { target c++20 } } |
| 19 |
// { dg-add-options strict_std } |
| 20 |
|
| 21 |
#include <ranges> |
| 22 |
#include <limits> |
| 23 |
|
| 24 |
void |
| 25 |
test01() |
| 26 |
{ |
| 27 |
// PR libstdc++/96042 |
| 28 |
using V = std::ranges::iota_view<long long, long long>; |
| 29 |
|
| 30 |
// In strict -std=c++20 mode there is no integer wider than long long, |
| 31 |
// so V's difference type is an integer-class type, [iterator.concept.winc]. |
| 32 |
// In practice this is either __int128 or __detail::__max_diff_type. |
| 33 |
using D = std::ranges::range_difference_t<V>; |
| 34 |
// Ensure that numeric_limits is correctly specialized for the type. |
| 35 |
using L = std::numeric_limits<D>; |
| 36 |
static_assert( L::is_specialized ); |
| 37 |
static_assert( L::is_signed ); |
| 38 |
static_assert( L::is_integer ); |
| 39 |
static_assert( L::is_exact ); |
| 40 |
static_assert( L::digits > std::numeric_limits<long long>::digits ); |
| 41 |
static_assert( L::digits10 == static_cast<int>(L::digits * 0.30103) ); |
| 42 |
static_assert( L::min() == (D(1) << L::digits) ); |
| 43 |
static_assert( L::max() == ~L::min() ); |
| 44 |
static_assert( L::lowest() == L::min() ); |
| 45 |
} |
| 46 |
|
| 47 |
#ifdef __SIZEOF_INT128__ |
| 48 |
void |
| 49 |
test02() |
| 50 |
{ |
| 51 |
// When the target supports __int128 it can be used in iota_view |
| 52 |
// even in strict mode where !integral<__int128>. |
| 53 |
using V = std::ranges::iota_view<__int128, __int128>; |
| 54 |
using D = std::ranges::range_difference_t<V>; // __detail::__max_diff_type |
| 55 |
using L = std::numeric_limits<D>; |
| 56 |
static_assert( L::is_specialized ); |
| 57 |
static_assert( L::is_signed ); |
| 58 |
static_assert( L::is_integer ); |
| 59 |
static_assert( L::is_exact ); |
| 60 |
static_assert( L::digits > std::numeric_limits<long long>::digits ); |
| 61 |
static_assert( L::digits10 == static_cast<int>(L::digits * 0.30103) ); |
| 62 |
static_assert( L::min() == (D(1) << L::digits) ); |
| 63 |
static_assert( L::max() == ~L::min() ); |
| 64 |
static_assert( L::lowest() == L::min() ); |
| 65 |
} |
| 66 |
#endif |