Skip to content

Commit b92742a

Browse files
committed
[libc++] Make views::iota aware of __int128
1 parent 478e45f commit b92742a

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

libcxx/include/__ranges/iota_view.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,17 @@ struct __get_wider_signed {
5858
return type_identity<int>{};
5959
else if constexpr (sizeof(_Int) < sizeof(long))
6060
return type_identity<long>{};
61-
else
61+
else if constexpr (sizeof(_Int) < sizeof(long long))
6262
return type_identity<long long>{};
63-
64-
static_assert(
65-
sizeof(_Int) <= sizeof(long long), "Found integer-like type that is bigger than largest integer like type.");
63+
# if _LIBCPP_HAS_INT128
64+
else if constexpr (sizeof(_Int) <= sizeof(__int128))
65+
return type_identity<__int128>{};
66+
# else
67+
else if constexpr (sizeof(_Int) <= sizeof(long long))
68+
return type_identity<long long>{};
69+
# endif
70+
else
71+
static_assert(false, "Found integer-like type that is bigger than largest integer like type.");
6672
}
6773

6874
using type = typename decltype(__call())::type;

libcxx/test/std/ranges/range.factories/range.iota.view/indices.pass.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include <vector>
1919

2020
#include "test_macros.h"
21-
#define TEST_HAS_NO_INT128 // Size cannot be larger than 64 bits
2221
#include "type_algorithms.h"
2322

2423
#include "types.h"

libcxx/test/std/ranges/range.factories/range.iota.view/iterator/member_typedefs.compile.pass.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,11 @@ void test() {
106106
// Same as below, if there is no type larger than long, we can just use that.
107107
static_assert(sizeof(Iter::difference_type) >= sizeof(long));
108108
static_assert(std::is_signed_v<Iter::difference_type>);
109+
#ifndef TEST_HAS_NO_INT128
110+
LIBCPP_STATIC_ASSERT(std::same_as<Iter::difference_type, __int128>);
111+
#else
109112
LIBCPP_STATIC_ASSERT(std::same_as<Iter::difference_type, long long>);
113+
#endif
110114
}
111115
{
112116
const std::ranges::iota_view<long long> io(0);
@@ -118,7 +122,11 @@ void test() {
118122
// https://eel.is/c++draft/range.iota.view#1.3
119123
static_assert(sizeof(Iter::difference_type) >= sizeof(long long));
120124
static_assert(std::is_signed_v<Iter::difference_type>);
125+
#ifndef TEST_HAS_NO_INT128
126+
LIBCPP_STATIC_ASSERT(std::same_as<Iter::difference_type, __int128>);
127+
#else
121128
LIBCPP_STATIC_ASSERT(std::same_as<Iter::difference_type, long long>);
129+
#endif
122130
}
123131
{
124132
const std::ranges::iota_view<Decrementable> io;

0 commit comments

Comments
 (0)