std::set,multiset



set,multiset

mapと同様の連想コンテナだが,キーと値を一緒に格納することが異なる. 値の一部をキーとする.multisetはキーの重複を許したバージョン.

インクルード

#include <set>

初期化(コンストラクタ)

explicit set(const Compare& comp = Compare(),
               const Allocator& = Allocator());
template <class InputIterator>
 set(InputIterator first, InputIterator last,
       const Compare& comp = Compare(), const Allocator& = Allocator());
set(const set<Key,Compare,Allocator>& x);

explicit multiset(const Compare& comp = Compare(),
                    const Allocator& = Allocator());
template <class InputIterator>
 multiset(InputIterator first, InputIterator last,
            const Compare& comp = Compare(), const Allocator& = Allocator());
multiset(const multiset<Key,Compare,Allocator>& x);

要素アクセス(begin,end,rbegin,rend)

  • begin(),end() : コンテナの最初のイテレータ,最後の次のイテレータを返す.イテレータを用いた要素アクセスに使用
    iterator begin ();
    const_iterator begin () const;
  • rbegin(),rend() : コンテナの最初の逆イテレータ,最後の次の逆イテレータを返す.イテレータを用いた要素逆順アクセスに使用
    reverse_iterator rend();
    const_reverse_iterator rend() const;

サイズ確認(size,max_size,empty)

  • size() : コンテナのサイズを返す関数
    size_type size() const;
  • max_size() : コンテナが確保可能な最大サイズを返す関数.予約領域ではない
    size_type max_size () const;
  • empty() : コンテナが空だったらtrueを返す関数
    bool empty () const;

編集(insert,erase,clear,swap)

  • insert(val) : 要素を挿入する.
    pair<iterator,bool> insert(const value_type& x);
    iterator insert(iterator position, const value_type& x);
    template <class InputIterator>
     void insert(InputIterator first, InputIterator last);
  • erase(iter) : 要素を削除する.
    void erase(iterator position);				// イテレータで示された位置の要素削除
    size_type erase(const key_type& k);			// キーがxである要素を削除
    void erase(iterator first, iterator last);	// イテレータで示された範囲の要素削除
  • clear() : コンテナのクリア.全要素を削除する.
    void clear();
  • swap() : 2つのコンテナのスワップ.
    void swap(set<Key,Compare,Allocator>& st);

マップの走査(find,count,lower_bound,upper_bound,equal_range)

  • find(k) : キーがxである要素を検索してそのイテレータを返す.見つからなければ末尾のイテレータ(end())が返される.
    iterator find(const key_type& k) const;
  • count(k) : マップ内のキーがxである要素の数を返す(mapでは0か1,multimapでは数)
    size_type count(cont key_type& k) const;
  • lower_bound(k) : キーがx以上である最初の要素を示すイテレータを返す
    iterator lower_bound(const key_type& k) const;
  • upper_bound(k) : キーがxより大きい最初の要素を示すイテレータを返す
    iterator upper_bound(const key_type& k) const;
  • equal_range(k) : キーがxである要素の範囲(イテレータのpair)を返す(mapでは1要素のみ)
    pair<iterator,iterator> equal_range(const key_type& k) const;

比較関数(key_comp,value_comp)

  • key_comp() : キーの比較関数オブジェクトを返す
    key_compare key_comp() const;
  • value_comp() : 値の比較関数オブジェクトを返す
    value_compare value_comp() const;

トップ   編集 凍結 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2024-03-08 (金) 18:06:08