0

Visual Studio 2022 (v143)这段代码用and编译得很好/std:c++latest

auto result{ ranges::istream_view<int>(cin)
    | views::take_while([](const auto& v) { return v != -1; })
};

但添加views::common

auto result{ ranges::istream_view<int>(cin)
    | views::take_while([](const auto& v) { return v != -1; })
    | views::common
};

让编译器抱怨:

Error (active)  E0349   no operator "|" matches these operands  Project19   C:\Project19\Project19\Source.cpp   75  
Error   C2678   binary '|': no operator found which takes a left-hand operand of type 'std::ranges::take_while_view<std::ranges::basic_istream_view<int,char,std::char_traits<char>>,_Ty>' (or there is no acceptable conversion)   Project19   C:\Project19\Project19\Source.cpp   74  
Error   C2119   'result': the type for 'auto' cannot be deduced from an empty initializer   Project19   C:\Project19\Project19\Source.cpp   73  

使用 range::views::iota 很好:

auto result{ views::iota(-10)
    | views::take_while([](const auto& v) { return v != -1; })
    | views::common
};

这是为什么?请包括参考资料以获得可能的解释。

4

0 回答 0