list::erase (STL/CLR)
指定した位置にある要素を削除します。
iterator erase(iterator where);
iterator erase(iterator first, iterator last);
パラメーター
まず
消去する範囲の先頭。last
消去する範囲の最後。where
消去する要素。
解説
一つ目のメンバー関数は whereが指す被制御シーケンスの要素を削除します。一つの要素を削除するときに使用します。
2 番目のメンバー関数は、範囲 [first,last)の被制御シーケンスの要素を削除します。ゼロ使用して以上の連続する要素を削除するためにも。
メンバー関数も、そのような要素が存在しない場合、削除された要素を超えていない最初の要素を指定するか、 list::end (STL/CLR)() 反復子を返します。
要素を消去するときに、要素のコピーの数は削除の末尾とシーケンスの近端での要素の数で直線的です。一つ以上の要素をシーケンスの先頭または末尾に消去するときに、 (要素のコピーは実行されません)。
使用例
// cliext_list_erase.cpp
// compile with: /clr
#include <cliext/list>
int main()
{
cliext::list<wchar_t> c1;
c1.push_back(L'a');
c1.push_back(L'b');
c1.push_back(L'c');
// display initial contents " a b c"
for each (wchar_t elem in c1)
System::Console::Write(" {0}", elem);
System::Console::WriteLine();
// erase an element and reinspect
System::Console::WriteLine("erase(begin()) = {0}",
*c1.erase(c1.begin()));
// add elements and display " b c d e"
c1.push_back(L'd');
c1.push_back(L'e');
for each (wchar_t elem in c1)
System::Console::Write(" {0}", elem);
System::Console::WriteLine();
// erase all but end
cliext::list<wchar_t>::iterator it = c1.end();
System::Console::WriteLine("erase(begin(), end()-1) = {0}",
*c1.erase(c1.begin(), --it));
System::Console::WriteLine("size() = {0}", c1.size());
return (0);
}
必要条件
ヘッダー:<cliext/リスト>
名前空間: の cliext