類模板
<set>

std::multiset

template < class T,                        // multiset::key_type/value_type           class Compare = less<T>,        // multiset::key_compare/value_compare           class Alloc = allocator<T> >    // multiset::allocator_type           > class multiset;
Multiple-key set
Multisets are containers that store elements following a specific order, and where multiple elements can have equivalent values.

multiset, the value of an element also identifies it (the value is itself the key, of typeT). The value of the elements in amultisetcannot be modified once in the container (the elements are always const), but they can be inserted or removed from the container.

在內部,multisetare always sorted following a specific strict weak ordering criterion indicated by its internal comparison object (of typeCompare).

multisetcontainers are generally slower than unordered_multiset containers to access individual elements by their key, but they allow the direct iteration on subsets based on their order.

Multisets are typically implemented as binary search trees.

容器屬性

關聯容器
關聯容器中的元素由其引用,而不是由其在容器中的絕對位置引用。
有序的
容器中的元素始終遵循嚴格的順序。所有插入的元素都會在此順序中獲得一個位置。
集合 (Set)
元素的值也是用於標識它的
多個等效鍵
Multiple elements in the container can have equivalent keys.
感知分配器
容器使用分配器物件來動態處理其儲存需求。

模板引數

T
Type of the elements. Each element in amultisetcontainer is also identified by this value (each value is itself also the element's key).
別名為成員型別multiset::key_typemultiset::value_type.
Compare
一個二元謂詞,它接受兩個與元素型別相同的引數並返回一個bool值。表示式comp(a,b),其中 comp 是此型別的物件,ab 是鍵值,如果 a 在該函式定義的嚴格弱序中被認為在 b 之前,則應返回true
要放回的字元的multiset物件使用此表示式來確定元素在容器中遵循的順序以及兩個元素鍵是否等效(透過自反比較它們:如果!comp(a,b) && !comp(b,a)).
This can be a function pointer or a function object (see constructor for an example). This defaults toless<T>,其返回結果與應用小於運算子 (a<b).
別名為成員型別multiset::key_comparemultiset::value_compare.
Alloc
用於定義儲存分配模型的分配器物件型別。預設情況下,使用 allocator 類模板,它定義了最簡單的記憶體分配模型並且與值無關。
別名為成員型別multiset::allocator_type.

成員型別

成員型別定義說明
key_type第一個模板引數 (T)
value_type第一個模板引數 (T)
key_compare第二個模板引數 (Compare)預設為less<key_type>
value_compare第二個模板引數 (Compare)預設為less<value_type>
allocator_type第三個模板引數 (Alloc)預設為allocator<value_type>
引用allocator_type::reference對於預設的 allocatorvalue_type&
const_referenceallocator_type::const_reference對於預設的 allocatorconst value_type&
指標allocator_type::pointer對於預設的 allocatorvalue_type*
const_pointerallocator_type::const_pointer對於預設的 allocatorconst value_type*
iterator指向value_type隨機訪問迭代器,可轉換為const_iterator
const_iterator指向const value_type
reverse_iteratorreverse_iterator<iterator>
const_reverse_iteratorreverse_iterator<const_iterator>
difference_type一個有符號整數型別,與iterator_traits<iterator>::difference_type相同,通常與 ptrdiff_t 一樣
size_type一個可以表示任何非負值的difference_type的無符號整數型別,通常與 size_t 一樣
成員型別定義說明
key_type第一個模板引數 (T)
value_type第一個模板引數 (T)
key_compare第二個模板引數 (Compare)預設為less<key_type>
value_compare第二個模板引數 (Compare)預設為less<value_type>
allocator_type第三個模板引數 (Alloc)預設為allocator<value_type>
引用value_type&
const_referenceconst value_type&
指標allocator_traits<allocator_type>::pointer對於預設的 allocatorvalue_type*
const_pointerallocator_traits<allocator_type>::const_pointer對於預設的 allocatorconst value_type*
iterator指向const value_type* 可轉換為const_iterator
const_iterator指向const value_type*
reverse_iteratorreverse_iterator<iterator>*
const_reverse_iteratorreverse_iterator<const_iterator>*
difference_type一個有符號整數型別,與
iterator_traits<iterator>::difference_type
相同,通常與 ptrdiff_t 一樣
size_type一個可以表示任何非負值的difference_type的無符號整數型別,通常與 size_t 一樣
*Note: All iterators in a multiset point to const elements. Whether theconst_成員型別是否與其非const_對應項是同一型別取決於具體的庫實現,但程式不應依賴於它們的不同來過載函式const_iterator更通用,因為iterator總是可以轉換為它。

成員函式


迭代器:

容量:

修改器:

觀察器:

操作:

分配器: