Skip to content

<ranges>: zip_transform does not accept non const iterable ranges #4414

Description

@dvirtz

Describe the bug

You can't feed ranges which are not const iterable, like filter_view, to zip_transform.
gcc with libstdc++ accepts this code.

test case

#include <ranges>

int main() {
    using namespace std::views;
    auto evens_and_odds =
        zip_transform([](int even, int odd) { return even + odd; },
                      iota(0, 10) | filter([](int i) { return i % 2 == 0; }),
                      iota(0, 10) | filter([](int i) { return i % 2 != 0; }));
}

error is

example.cpp
C:/data/msvc/14.38.33133/include\ranges(8872): error C7602: 'std::ranges::range_reference_t': the associated constraints are not satisfied
C:/data/msvc/14.38.33133/include\xutility(2661): note: see declaration of 'std::ranges::range_reference_t'
C:/data/msvc/14.38.33133/include\xutility(2660): note: the concept 'std::ranges::range<const std::ranges::filter_view<std::ranges::iota_view<_Ty1,_Ty2>,main::<lambda_2>>>' evaluated to false
        with
        [
            _Ty1=int,
            _Ty2=int
        ]
C:/data/msvc/14.38.33133/include\xutility(2468): note: call to object of class type 'std::ranges::_Begin::_Cpo': no matching call operator found
C:/data/msvc/14.38.33133/include\xutility(2371): note: could be 'auto std::ranges::_Begin::_Cpo::operator ()(_Ty &&) noexcept(<expr>) const'
C:/data/msvc/14.38.33133/include\ranges(8872): note: the template instantiation context (the oldest one first) is
C:/data/msvc/14.38.33133/include\ranges(8969): note: see reference to variable template 'const bool std::ranges::views::_Zip_transform_fn::_Enable_cpo<`main'::`2'::<lambda_1>,std::ranges::filter_view<std::ranges::iota_view<int,int>,`main'::`2'::<lambda_2> >,std::ranges::filter_view<std::ranges::iota_view<int,int>,`main'::`2'::<lambda_3> > >' being compiled
C:/data/msvc/14.38.33133/include\ranges(8962): note: see reference to class template instantiation 'std::ranges::zip_transform_view<_Func,std::ranges::filter_view<std::ranges::iota_view<_Ty1,_Ty2>,main::<lambda_2>>,std::ranges::filter_view<std::ranges::iota_view<_Ty1,_Ty2>,main::<lambda_3>>>' being compiled
        with
        [
            _Func=main::<lambda_1>,
            _Ty1=int,
            _Ty2=int
        ]
C:/data/msvc/14.38.33133/include\ranges(8872): error C2065: '<missingId>': undeclared identifier
Compiler returned: 2

https://godbolt.org/z/o41csG3jr

Expected behavior

Code compiles without an error

STL version

Microsoft (R) C/C++ Optimizing Compiler Version 19.38.33133 for x64

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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