std::unordered_set<Key,Hash,KeyEqual,Allocator>::unordered_set
| (1) | ||
unordered_set() : unordered_set(size_type(/* 未指定 */)) {} |
(C++11 起) (直到 C++20) |
|
| unordered_set(); |
(自 C++20 起) | |
| explicit unordered_set( size_type bucket_count, const Hash& hash = Hash(), |
(2) | (C++11 起) |
| unordered_set( size_type bucket_count, const Allocator& alloc ) |
(3) | (C++14 起) |
| unordered_set( size_type bucket_count, const Hash& hash, |
(4) | (C++14 起) |
| explicit unordered_set( const Allocator& alloc ); |
(5) | (C++11 起) |
| template< class InputIt > unordered_set( InputIt first, InputIt last, |
(6) | (C++11 起) |
| template< class InputIt > unordered_set( InputIt first, InputIt last, |
(7) | (C++14 起) |
| template< class InputIt > unordered_set( InputIt first, InputIt last, |
(8) | (C++14 起) |
| unordered_set( const unordered_set& other ); |
(9) | (C++11 起) |
| unordered_set( const unordered_set& other, const Allocator& alloc ); |
(10) | (C++11 起) |
| unordered_set( unordered_set&& other ); |
(11) | (C++11 起) |
| unordered_set( unordered_set&& other, const Allocator& alloc ); |
(12) | (C++11 起) |
unordered_set( std::initializer_list<value_type> init, size_type bucket_count = /* 未指定 */, |
(13) | (C++11 起) |
| unordered_set( std::initializer_list<value_type> init, size_type bucket_count, |
(14) | (C++14 起) |
| unordered_set( std::initializer_list<value_type> init, size_type bucket_count, |
(15) | (C++14 起) |
template< container-compatible-range<value_type> R > unordered_set( std::from_range_t, R&& rg, |
(16) | (自 C++23 起) |
| template< container-compatible-range<value_type> R > unordered_set( std::from_range_t, R&& rg, |
(17) | (自 C++23 起) |
| template< container-compatible-range<value_type> R > unordered_set( std::from_range_t, R&& rg, |
(18) | (自 C++23 起) |
從各種資料來源建構新容器。可選擇性使用使用者提供的 bucket_count 作為建立的最小桶數,hash 作為雜湊函數,equal 作為鍵值比較函數,以及 alloc 作為分配器。
[first, last) 中的內容建構容器。將 max_load_factor() 設為 1.0。若範圍內有多個元素的鍵值比較相等,則插入哪一個元素是不確定的(待處理 LWG2844)。|
樣板參數 |
(自 C++23 起) |
|
樣板參數 |
(自 C++23 起) |
目錄 |
[edit] 參數
| alloc | - | 用於此容器所有記憶體配置的配置器 |
| bucket_count | - | 初始化時使用的最小桶數。若未指定,將使用一個未指定的預設值 |
| hash | - | 要使用的雜湊函數 |
| equal | - | 此容器進行所有鍵值比較時所使用的比較函數 |
| first, last | - | 定義要複製的元素之來源範圍的迭代器對 |
| rg | - | 一個 容器相容範圍,即一個其元素可轉換為 value_type 的 input_range |
| 其他 | - | 另一個用作來源以初始化容器元素的容器 |
| init | - | 用於初始化容器元素的初始化列表 |
| 類型要求 | ||
-InputIt 必須符合 傳統輸入迭代器 (LegacyInputIterator) 的要求。 | ||
[edit] 複雜度
[edit] 例外
對 Allocator::allocate 的呼叫可能拋出例外。
[edit] 備註
other 的參考、指標與迭代器(結束迭代器除外)仍然有效,但會指向目前位於 *this 中的元素。現行標準透過 [container.reqmts]/67 中的廣泛陳述提供此項保證,更直接的保證正透過 LWG issue 2321 研議中。儘管在 C++23 之前並未正式要求,但一些實作在早期模式中就已將樣板參數 Allocator 置入 非推導情境 中。
| 功能測試巨集 | 數值 | 標準 | 功能 |
|---|---|---|---|
__cpp_lib_containers_ranges |
202202L |
(C++23) | 範圍感知建構與插入;多載 (16-18) |
[edit] 範例
| 本節尚不完整 理由:無範例 |
[edit] 缺陷報告
下列更改行為的缺陷報告追溯應用於之前的 C++ 標準。
| DR | 應用於 | 出版時的行為 | 正確的行為 |
|---|---|---|---|
| LWG 2193 | C++11 | 預設建構函式 (1) 為 explicit | 改為非 explicit |
| LWG 2230 | C++11 | 多載 (13) 的語意未指定 | 已指定 |
[edit] 參見
| 指派值給容器 (公開成員函式) |