相关疑难解决方法(0)

对于简单的 std::ranges 代码,某些编译器存在错误或编译错误

我有一段使用 C++20 范围库的代码,取自此 SO anwer。该代码被某些编译器(版本)拒绝,并且某些较旧的 GCC 版本返回垃圾。哪个编译器是正确的?

该代码应该打印 a 中第一列的元素std::vector<std::vector>

#include <vector>
#include <string>
#include <ranges>
#include <iostream>

int main()
{
    // returns a range containing only the i-th element of an iterable container
    auto ith_element = [](size_t i) {
        // drop the first i elements in the range and take the first element from the remaining range
        return std::views::drop(i) | std::views::take(1);
    };

    // returns a range over the i-th column
    auto column = [ith_element](size_t i) …
Run Code Online (Sandbox Code Playgroud)

c++ c++20 std-ranges

11
推荐指数
1
解决办法
742
查看次数

标签 统计

c++ ×1

c++20 ×1

std-ranges ×1