c ++ 11:使用const_iterator进行擦除 [英] c++11: erase using a const_iterator

查看:260
本文介绍了c ++ 11:使用const_iterator进行擦除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我相信自从C ++ 11以来,大多数容器的 erase 函数(例如 std :: vector )接受 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);

仍然是我的编译器(GCC 4.8和Clang 3.2,都使用GCC libstdc ++)即使使用 - std = c ++ 11

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.

编译也是一个编译器/ libstdc ++ bug,还是我做错了?这是一个示例代码:

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;
}


推荐答案

href =http://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html>此处,并且现在报告为部分实施。

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

CTRL + F ,并搜索 N2350

如果你在Linux上,可以从LLVM项目中创建 libcxx 库的开发版本,你可以从这里;我不知道这是否解决了你遇到的任何问题,但我建议它作为 libstdc ++ 的替代。

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++.

这篇关于c ++ 11:使用const_iterator进行擦除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆