Thanks to visit codestin.com
Credit goes to github.com

Skip to content

<ranges>: views::repeat(...) | views::take(...) is not always a valid range #3392

@JMazurkiewicz

Description

@JMazurkiewicz

Command-line test case

#include <ranges>

using namespace std;

const auto rice = views::repeat("🌾"sv, 100zu); // difference_type is _Signed128
const auto taken_rice = rice | views::take(3);
static_assert(ranges::range<decltype(taken_rice)>); // error!
PS D:\stl-playground> clang-cl /std:c++latest /Zs .\iota_diff.cpp
In file included from .\iota_diff.cpp:1:
In file included from D:\stl\Out\build\x64\out\inc\ranges:16:
In file included from D:\stl\Out\build\x64\out\inc\iterator:12:
In file included from D:\stl\Out\build\x64\out\inc\xutility:12:
D:\stl\Out\build\x64\out\inc\__msvc_iter_core.hpp(96,1): error: no type named 'difference_type' in 'std::incrementable_traits<std::_Signed128>'
using iter_difference_t = typename conditional_t<_Is_from_primary<iterator_traits<remove_cvref_t<_Ty>>>,
^~~~~
[...]

The main reason of this error is that _Signed128 does not model weakly_incrementable.

Expected behavior
This code should compile.

Additional context
The truth is that standard does not require _Signed128 to model weakly_incrementable ([range.iota.view]/1), but it would be very nice if it did:

#include <ranges>

using namespace std;

using X = ranges::_Iota_diff_t<size_t>;
static_assert(!weakly_incrementable<X>);
using Y = ranges::_Iota_diff_t<X>; // <= compile error

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixedSomething works now, yay!rangesC++20/23 ranges

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions