std::map::erase inquiry

So if I had a map m and a set s, could I use erase() in a way where I can erase from m everything from the beginning of s to the end of s? like so:
 
m.erase(s.begin().s.end());

Was I not allowed to jump in between different containers like that?
for( auto& key : set ) map.erase(key) ; // simplest, not the most efficient
Eh, it works. I get that auto lets the compiler decide what variable is declared, but I'm still a bit slow on why auto works in the context of this problem. I'll try to figure it out. thanks
> I'm still a bit slow on why auto works in the context of this problem.

for( auto& key : set ) map.erase(key) ;

is equivalent to:
1
2
3
4
5
6
for( auto iter = set.begin(), end_iter = set.end() ; iter != end_iter ; ++iter )
{
    auto& key = *iter ;

    map.erase(key) ;
}
closed account (E0p9LyTq)
omega4relay wrote:
I'm still a bit slow on why auto works in the context of this problem.

Range-based for statements
http://www.learncpp.com/cpp-tutorial/b-3-range-based-for-statements-and-static_assert/
Topic archived. No new replies allowed.