Is there a good way to convert a 2D C ++ array to pairs?

I have a 2d array under an action {{1,2},{3,4},{5,6}...}

or similar. I would like to convert each row to a pair to insert them as vertices into an offset adjacency list graph. What's the best way to do this (i.e. convert each string to a pair)?

+3


source to share


1 answer


Iterating over an external array and constructing objects std::pair

with:

std::pair<int,int>(arr[i][0],arr[i][1]);



For example:

std::vector<std::pair<int,int>> vec;
for (auto & inner : arr) vec.emplace_back(inner[0],inner[1]);

      

+5


source







All Articles