Błąd kompilacji przy próbie usunięcia elementu z listy za pomocą const_iteratora

0
#include <list>
using namespace std;

int main() {
	list<int> l;
	l.push_front(1);
	
	list<int>::const_iterator it = l.begin();
	l.erase(it);
	return 0;
}

http://ideone.com/2AQyb6

Kompilacja jako C++11 (!) wyrzuca mi następujące błędy:

prog.cpp: In function ‘int main()’:
prog.cpp:9:12: error: no matching function for call to ‘std::list<int>::erase(std::list<int>::const_iterator&)’
  l.erase(it);
            ^
prog.cpp:9:12: note: candidates are:
In file included from /usr/include/c++/4.8/list:64:0,
                 from prog.cpp:1:
/usr/include/c++/4.8/bits/list.tcc:108:5: note: std::list<_Tp, _Alloc>::iterator std::list<_Tp, _Alloc>::erase(std::list<_Tp, _Alloc>::iterator) [with _Tp = int; _Alloc = std::allocator<int>; std::list<_Tp, _Alloc>::iterator = std::_List_iterator<int>]
     list<_Tp, _Alloc>::
     ^
/usr/include/c++/4.8/bits/list.tcc:108:5: note:   no known conversion for argument 1 from ‘std::list<int>::const_iterator {aka std::_List_const_iterator<int>}’ to ‘std::list<int>::iterator {aka std::_List_iterator<int>}’
In file included from /usr/include/c++/4.8/list:63:0,
                 from prog.cpp:1:
/usr/include/c++/4.8/bits/stl_list.h:1193:7: note: std::list<_Tp, _Alloc>::iterator std::list<_Tp, _Alloc>::erase(std::list<_Tp, _Alloc>::iterator, std::list<_Tp, _Alloc>::iterator) [with _Tp = int; _Alloc = std::allocator<int>; std::list<_Tp, _Alloc>::iterator = std::_List_iterator<int>]
       erase(iterator __first, iterator __last)
       ^
/usr/include/c++/4.8/bits/stl_list.h:1193:7: note:   candidate expects 2 arguments, 1 provided

Z tego, co zrozumiałem, to kompilator chce, żebym podał zwykły iterator, a nie const_iterator. Bzdura jakaś, w dokumentacji http://www.cplusplus.com/reference/list/list/erase/ jest napisane, że list::erase akceptuje const_iterator jako argument w C++11!

Więc ostatecznie, nie pojmuję.

0

W GCC 4.8.2 tego po prostu nie ma.
http://gcc.gnu.org/onlinedocs/gcc-4.8.2/libstdc++/manual/manual/status.html#status.iso.2011 i poszukaj "N2350"

W GCC 4.9 zostnie to naprawione, bo w najnowszej dokumentacji już nie ma tych uwag.

0

Dzięki.

1 użytkowników online, w tym zalogowanych: 0, gości: 1