lundi 13 septembre 2021

How to avoid an explicit loop when pulling out a vector of a particular member from a vector of a class containing that member

Suppose I have a class

struct Foo {double x; double y;}

and std::vector<Foo> xy;

I also have a function to pull out the x members:

std::vector<double> bar(const std::vector<Foo>& xy);

which loops through each element of xy.

Is there a way of using the C++ standard library so I can avoid an explicit for loop?

Aucun commentaire:

Enregistrer un commentaire