stl::list への (非 const) 参照と、そのリスト内の特定の場所への const_iterator がある場合、同じ場所を指す反復子を取得するにはどうすればよいですか? (その位置の要素を消去したいのですが、リストには const_iterators の消去メソッドがありません)
リストへの非定数参照がある場合にのみ機能するため、これは定数の正確性に違反するべきではないようです。
編集:
ちょっと待って、CPP リファレンスを見てください: http://www.cplusplus.com/reference/list/list/erase/それはあなたが const_iterator で erase() を呼び出すことができると言います。では、なぜ私のコンパイラは不平を言っているのでしょうか? gcc 4.6 --std=c++0x を使用しています
エラーは次のとおりです。
g++ -D__GXX_EXPERIMENTAL_CXX0X__ -O0 -g3 -Wall --std=c++0x -c -fmessage-length=0 -MMD -MP -MF"src/constraint.d" -MT"src/constraint.d" -o "src/constraint.o" "../src/constraint.cpp"
../src/constraint.cpp: In member function ‘void constraint::remove_lit(std::list<std::pair<literal, int> >::const_iterator)’:
../src/constraint.cpp:144:18: error: no matching function for call to ‘std::list<std::pair<literal, int> >::erase(std::list<std::pair<literal, int> >::const_iterator&)’
../src/constraint.cpp:144:18: note: candidates are:
/usr/include/c++/4.6/bits/list.tcc:109:5: note: std::list<_Tp, _Alloc>::iterator std::list<_Tp, _Alloc>::erase(std::list<_Tp, _Alloc>::iterator) [with _Tp = std::pair<literal, int>, _Alloc = std::allocator<std::pair<literal, int> >, std::list<_Tp, _Alloc>::iterator = std::_List_iterator<std::pair<literal, int> >]
/usr/include/c++/4.6/bits/list.tcc:109:5: note: no known conversion for argument 1 from ‘std::list<std::pair<literal, int> >::const_iterator {aka std::_List_const_iterator<std::pair<literal, int> >}’ to ‘std::_List_iterator<std::pair<literal, int> >’
/usr/include/c++/4.6/bits/stl_list.h:1160:7: note: std::list<_Tp, _Alloc>::iterator std::list<_Tp, _Alloc>::erase(std::list<_Tp, _Alloc>::iterator, std::list<_Tp, _Alloc>::iterator) [with _Tp = std::pair<literal, int>, _Alloc = std::allocator<std::pair<literal, int> >, std::list<_Tp, _Alloc>::iterator = std::_List_iterator<std::pair<literal, int> >]
/usr/include/c++/4.6/bits/stl_list.h:1160:7: note: candidate expects 2 arguments, 1 provided
make: *** [src/constraint.o] Error 1