Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c++11: erase using a const_iterator

I believe that since C++11, the erase function of most containers (e.g. std::vector) accepts a const_iterator as parameter:

iterator erase (const_iterator position);

Still my compilers (GCC 4.8 and Clang 3.2, both using GCC libstdc++) won't allow me to use such function, even when compiling with --std=c++11.

Is it a compiler/libstdc++ bug, or did I do something bad? This is a sample code:

#include <vector>

int main( )
{
    std::vector<int> v;
    v.push_back( 1 );
    v.push_back( 2 );
    v.push_back( 3 );

    std::vector<int>::const_iterator i = v.begin();
    while( i != v.end() ) {
        i = v.erase( i );
    }

    return 0;
}
like image 228
peoro Avatar asked Apr 13 '13 12:04

peoro


1 Answers

This issue is documented here and it's reported as a partial implementation for now.

CTRL + F with your browser and search for N2350.

If you are on Linux it's possible to build a development version of the libcxx library from the LLVM project that you can download from here; I don't know if this solves any of the issues that you are experiencing but I'm proposing it as an alternative to the libstdc++.

like image 82
user2244984 Avatar answered Oct 07 '22 10:10

user2244984