Hi,
say I have a vector v1:
std::vector<Som eType> v1;
and I need a vector v2 of pointers to v1's elements:
std::vector<Som eType*> v2;
std::vector<Som eType>::iterato r iter;
for( iter = v1.begin(); iter != v1.end(), ++iter )
v2.push_back( &(*iter) );
Now is there a more elegant way to initialize v2 instead of looping
through v1 and pushing back the *iter's address to v2?
Something like "for each elem in v1 insert its address into v2"?
Having a loop which only consists of a single insert operation, I have
the feeling this may be better expressed with some STL algo.
--
Regards,
Matthias
say I have a vector v1:
std::vector<Som eType> v1;
and I need a vector v2 of pointers to v1's elements:
std::vector<Som eType*> v2;
std::vector<Som eType>::iterato r iter;
for( iter = v1.begin(); iter != v1.end(), ++iter )
v2.push_back( &(*iter) );
Now is there a more elegant way to initialize v2 instead of looping
through v1 and pushing back the *iter's address to v2?
Something like "for each elem in v1 insert its address into v2"?
Having a loop which only consists of a single insert operation, I have
the feeling this may be better expressed with some STL algo.
--
Regards,
Matthias
Comment