#include <ranges>
#include <algorithm>
#include <vector>
using namespace std;
struct Edge{int from, to;};
const vector<int> v1 = {1, 1} , v2 = {2,2};
vector<Edge> v3 = views::zip( v1, v2) | ranges::to<vector>();
compilation using g++14.
prog.cc:10:38: error: conversion from 'vector<std::tuple<int, int>,allocator<std::tuple<int, int>>>' to non-scalar type 'vector<Edge,allocator>' requested
Can this be fixed without doing (painfully verbose):
#include <ranges>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
struct Edge{int from, to;};
const vector<int> v1 = {1, 1} , v2 = {2,2};
vector<Edge> v3 = views::zip( v1, v2) | views::transform([](const auto arg){const auto [a, b]=arg; return Edge{a,b};}) | ranges::to<vector>();
}
With C++23 comes zip_transform which could reduce it to this