I have an data named faces which definition is like this:
struct ivec3 {
unsigned int v0;
unsigned int v1;
unsigned int v2;
};
std::vector<ivec3> faces;
I got the faces with 100 elements(faces.size()=100).
Now I want to get all v0 of faces. If I use the Python, I can do it like this
all_v0 = faces[:, 0]
So, how can I use the slicing operation in C++ like above code of Python?
Thanks very much!
>Solution :
You can do this with the help of std::transform:
std::vector<int> all_v0;
all_v0.reserve(faces.size());
std::transform(faces.begin(), faces.end(),
std::back_inserter(all_v0),
[] (const ivec3& i) { return i.v0; });