Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions libcxx/include/__ranges/iota_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -363,15 +363,14 @@ namespace ranges {
(integral<_Start> && integral<_BoundSentinel>) || sized_sentinel_for<_BoundSentinel, _Start>
{
if constexpr (__integer_like<_Start> && __integer_like<_BoundSentinel>) {
if (__value_ < 0) {
if (__bound_sentinel_ < 0) {
return std::__to_unsigned_like(-__value_) - std::__to_unsigned_like(-__bound_sentinel_);
}
return std::__to_unsigned_like(__bound_sentinel_) + std::__to_unsigned_like(-__value_);
}
return std::__to_unsigned_like(__bound_sentinel_) - std::__to_unsigned_like(__value_);
return (__value_ < 0)
? ((__bound_sentinel_ < 0)
? std::__to_unsigned_like(-__value_) - std::__to_unsigned_like(-__bound_sentinel_)
: std::__to_unsigned_like(__bound_sentinel_) + std::__to_unsigned_like(-__value_))
: std::__to_unsigned_like(__bound_sentinel_) - std::__to_unsigned_like(__value_);
} else {
return std::__to_unsigned_like(__bound_sentinel_ - __value_);
}
return std::__to_unsigned_like(__bound_sentinel_ - __value_);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@

// constexpr auto size() const requires see below;

#include <ranges>
#include <cassert>
#include <concepts>
#include <limits>
#include <ranges>

#include "test_macros.h"
#include "types.h"
Expand Down Expand Up @@ -89,6 +90,15 @@ constexpr bool test() {
assert(io.size() == 0);
}

// Make sure iota_view<short, short> works properly. For details,
// see https://github.com/llvm/llvm-project/issues/67551.
{
static_assert(std::ranges::sized_range<std::ranges::iota_view<short, short>>);
std::ranges::iota_view<short, short> io(10, 20);
std::same_as<unsigned int> auto sz = io.size();
assert(sz == 10);
}

return true;
}

Expand Down