keith wrote:
>
>> It's a defect in the standard. See, e.g, issue 355 in:
>> http://www.open-std.org/jtc1/sc22/wg...004/n1685.html
>>
>> Also: the bug has been fixed in the draft for C++0X.
>
> I see. How then to erase the last element of a std::multimap<>? I've
> tried mmap.erase(mmap.rbegin());, but it does not work.
> mmap.erase(--mmap.end()), does work however. I don't see the construct
> being wrong for a std::multimap<>::iterator (or any other associate
> iterator), because they are not random but bidirectional. Consequently I
> see them being of class type.
a) Whether std::multimap<>::iterator is of class type is of no consequence
since operator-- does not need to be implemented as a member function
[17.3.1.2/3]. If it is a free function, the temporary mmap.end() will not
bind to its argument.
b) As for how to erase the last element: you can use a little helper
function:
template < typename Iter >
Iter prev ( Iter i ) {
-- i;
return ( i );
}
and then say: mmap.erase( prev( mmap.end() ) ). Of course, you can also
ditch the goal of doing it in one line
Best
Kai-Uwe Bux