peter55555
peter55555

Reputation: 1475

Filling a container with iterators from another container

I have a std::map<int, int> and a std::list<std::map<int, int>::const_iterator>.

Can I use an STL-algorithm to fill the list with all the iterators from the map in order?
I don't want to use an explicit loop if possible.

Upvotes: 0

Views: 566

Answers (1)

Columbo
Columbo

Reputation: 60999

The algorithms in the STL call functors with values, not with iterators. If you are obsessed with avoiding explicit loops then you might try to use iota with an iterator as a value:

list.resize(map.size());
std::iota( std::begin(list), std::end(list), std::begin(map) );

Demo.

Upvotes: 7

Related Questions