【C++学習】set

1828 ワード

setは、一意性を満たす集合であり、C++の標準ライブラリsetはクラステンプレートであり、
template < class T,                        // set::key_type/value_type
           class Compare = less<T>,        // set::key_compare/value_compare
           class Alloc = allocator<T>      // set::allocator_type
           > class set;

正常に使用するには、カテゴリパラメータを指定する必要があります.
set<string> str_set;

カスタムカテゴリの場合、2番目のパラメータ:コンパレータを指定する必要があります.
setのデータは常に秩序正しく保存されており、無秩序なsetを使用する必要がある場合はunordered_を使用する必要があります.setクラス.
データがsetに格納されると変更はできませんが、削除してから新しいデータを再挿入することで暗黙的に変更できます.
よく使用されるクラス変数:
iterator;//    
const_iterator;//     
reverse_iterator;//     

一般的な関数:
//1.    , map
begin;
end;
rbegin;
rend;
cbegin;
cend;
crbegin;
crend;

//  
empty();
size();

//    

insert()
erase()
swap()
clear()
find()
count()