4

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.

5
  • 3
    auto it = vector.cbegin(); if you don't like the long iterator name. ;) Commented Jun 7, 2013 at 6:48
  • GCC 4.8 with -std=c++11 Commented Jun 7, 2013 at 6:48
  • @Xeo: Using just "auto" here would not make vectorIter a const_iterator which is what was intended. Commented Jun 7, 2013 at 7:01
  • 3
    @sellibitze note about cbegin(), cbegin() returns const_iterator in all cases. Commented Jun 7, 2013 at 7:02
  • @ForEveR: Oh, right. I didn't see that little extra character Xeo's comment. Sorry, for the trouble. Commented Jun 7, 2013 at 18:57

5 Answers 5

4

In HERE:

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! Now I know where to get a detailed information about C++11.
4

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.

2 Comments

@Kolyunya so do I :) (for experimental use and if you are ok to build it yourself, the snapshots are already available)
I would be so incredibly happy if I could use a native g++ on unix, but I'm being forced to use mingw on win...
3

Have a look at gcc's library implementation status. There it clearly states that the feature in question hasn't been implemented yet:

23.3.6 - Class template vector - Partial - insert and erase members do not take const_iterator arguments (N2350).

1 Comment

Thank you! Now I know where to get a detailed information about C++11.
2

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

The simplest way for you to check is to have a peek at the underlying implementation of std::vector. Though most of it can be quite arcane, method signatures are usually easy enough to read.

Comments

1

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

Since 4.7 is not granted to be full compliant, this cannot be considered (In strict technical terms) an "error". May be it was a need to retain some compatibility with other library modules not compliant yet.

If this happens in 4.8 then it has to be considered a bug. But not in 4.7

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.