Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Erasing from an STL container by a constant iterator

According the the C++ reference STL containers were fixed in C++11 standard to take constant iterator in the erase methods. The following code would not compile in g++4.7 with c++0x enabled.

#include <vector>

int main()
{
    std::vector<int> vector;
    vector.push_back(0);

    std::vector<int>::const_iterator vectorItr = vector.begin();
    vector.erase(vectorItr);
}

Obviously the new signatures were not implemented. Is there any information when this issue will be fixed? I could not find any respective information in the C++0x/C++11 Support in GCC article.

like image 229
Kolyunya Avatar asked Dec 08 '22 15:12

Kolyunya


2 Answers

In HERE:

Section: 23.3.6
Description: Class template vector
Status: Partial
Comments: insert and erase members do not take const_iterator arguments (N2350).

like image 155
Mark Garcia Avatar answered Dec 11 '22 10:12

Mark Garcia


For what it's worth: I've tested this against GCC 4.8.1 as well as GCC 4.9 (20130602 snapshot) just now, and the result is that 4.8.1 still has this problem (note that the promised C++11 compliance is related to the language core, not the standard library), but the 4.9 snapshot compiles it correctly.

So I guess it's fair to assume that GCC 4.9, once released, will handle this as specified by the Standard.

like image 24
jogojapan Avatar answered Dec 11 '22 08:12

jogojapan