次の方法で共有


unordered_set::erase

指定した位置にある要素を削除します。

iterator erase(iterator where);
iterator erase(iterator first, iterator last);
size_type erase(const Key& keyval);

パラメーター

  • first
    消去する範囲の先頭。

  • key
    消去するキー値。

  • last
    消去する範囲の最後。

  • where
    消去する要素。

解説

1 つ目のメンバー関数は、where が指す被制御シーケンスの要素を削除します。2 つ目のメンバー関数は、[first, last) の範囲内の要素を削除します。どちらも、要素を削除した後に残った要素のうち最初の要素を指定する反復子を返します。このような要素が存在しない場合は unordered_set::end() が返されます。

3 つ目のメンバー関数は、unordered_set::equal_range(keyval) で区切られた範囲内の要素を削除します。削除された要素の数が返されます。

このメンバー関数では、例外はスローされません。

使用例

 

// std_tr1__unordered_set__unordered_set_erase.cpp 
// compile with: /EHsc 
#include <unordered_set> 
#include <iostream> 
 
typedef std::unordered_set<char> Myset; 
int main() 
    { 
    Myset c1; 
 
    c1.insert('a'); 
    c1.insert('b'); 
    c1.insert('c'); 
 
// display contents " [c] [b] [a]" 
    for (Myset::const_iterator it = c1.begin(); 
        it != c1.end(); ++it) 
        std::cout << " [" << *it << "]"; 
    std::cout << std::endl; 
 
// erase an element and reinspect 
    Myset::iterator it2 = c1.erase(c1.begin()); 
    std::cout << "*erase(begin()) == [" << *it2 << "]"; 
    std::cout << std::endl; 
 
// add elements and display " [e] [d] [b] [a]" 
    c1.insert('d'); 
    c1.insert('e'); 
 
    for (Myset::const_iterator it = c1.begin(); 
        it != c1.end(); ++it) 
        std::cout << " [" << *it << "]"; 
    std::cout << std::endl; 
 
// erase all but end; 
    it2 = c1.end(); 
    it2 = c1.erase(c1.begin(), --it2); 
    std::cout << "*erase(begin(), end()-1) == [" 
        << *it2 << "]" << std::endl; 
    std::cout << "size() == " << c1.size() << std::endl; 
 
    return (0); 
    } 
 
  

必要条件

ヘッダー : <unordered_set>

名前空間: std

参照

関連項目

<unordered_set>

unordered_set クラス

unordered_set::clear

その他の技術情報

<unordered_set> メンバー