That should work.
std::vector<int> lv;
std::transform(std::begin(la), std::end(la), std::back_inserter(lv), [](const A& a){
return a.color;
});
There is also another way:
Restore your structure to get color from the method:
struct A
{
int color;
A(int p_f) : color(p_f) {}
int getColor() const {
return color;
}
};
In this case you can use bind:
std::transform(std::begin(la), std::end(la), std::back_inserter(lv), std::bind(&A::getColor, std::placeholders::_1));
Or you can also use std::mem_fnfor a method that is a little shorter (thanks to @Piotr S.):
std::transform(std::begin(la), std::end(la), std::back_inserter(lv), std::mem_fn(&A::getColor));
std::mem_fn . getter:
std::transform(std::begin(la), std::end(la), std::back_inserter(lv), std::mem_fn(&A::color));