我有一段使用 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)