Removing from the STL container with a constant iterator

According to the C ++ reference, the STL containers have been fixed in the C ++ 11 standard to use the constant iterator in erase methods. The following code will 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, new signatures were not implemented. Is there any information when this problem is fixed? I could not find the relevant information in C ++ 0x / C ++ 11 in a GCC article .

+4
source share
5 answers

HERE :

Section: 23.3.6
Description: Template Vector Template
Status: Partial
Comments: insert and erase elements do not accept const_iterator (N2350) arguments.

+4
source

What is it worth: I tested it against GCC 4.8.1, as well as GCC 4.9 (snapshot 20130602) now, and the result is that 4.8.1 still has this problem (note that the promised C ++ 11 matches the core of the language, not the standard library), but the 4.9 snapshot compiles it correctly.

Therefore, I suppose it is fair to assume that GCC 4.9, after its release, will handle this as stated in the standard.

+4
source

Look at gcc library implementation status . There he clearly states that this function has not yet been implemented:

23.3.6 - Class template vector - Partial - inserting and deleting elements do not accept const_iterator (N2350) arguments.

+3
source

Unsurprisingly: since it has not yet been implemented, it seems ( even in C ++ 11 mode).

The easiest way to check is to look into the basic implementation of std::vector . Although most of them can be rather cryptic, method signatures are usually fairly easy to read.

+2
source

Full C ++ 11 compliance is given in GCC 4.8 (not 4.7).

Since 4.7 is not provided fully compatible, this cannot be considered (in strict technical terms) a "mistake". It may have been necessary to maintain some compatibility with other library modules that do not meet the requirements.

If this happens in 4.8, then this should be considered a mistake. But not in 4.7

+1
source

Source: https://habr.com/ru/post/1484981/


All Articles