I have a code that looks something like this:
struct First
{
int f1;
int f2;
};
struct Second
{
First s1;
int s2;
};
std::vector < Second > secondVec;
Second sec;
sec.s1 = First();
secondVec.push_back(sec);
secondVec.push_back(sec);
std::vector < First > firstVec;
firstVec.reserve(secondVec.size());
for (std::vector < Second >::iterator secIter = secondVec.begin();
secIter != = secondVec.end();
++secIter)
{
firstVec.push_back(secIter->s1);
}
I'd like to replace this ugly for
loop with a simple stl function that could perhaps perform the equivalent process. I was thinking that maybe std::transform
could help me here, but I'm unsure as to how this could be written.
I'd also be interested if boost has anything to offer here.