cplusplus
.com
教程
參考
文章
論壇
C++
教程
參考
文章
論壇
參考
C 庫
<cassert> (assert.h)
<cctype> (ctype.h)
<cerrno> (errno.h)
C++11
<cfenv> (fenv.h)
<cfloat> (float.h)
C++11
<cinttypes> (inttypes.h)
<ciso646> (iso646.h)
<climits> (limits.h)
<clocale> (locale.h)
<cmath> (math.h)
<csetjmp> (setjmp.h)
<csignal> (signal.h)
<cstdarg> (stdarg.h)
C++11
<cstdbool> (stdbool.h)
<cstddef> (stddef.h)
C++11
<cstdint> (stdint.h)
<cstdio> (stdio.h)
<cstdlib> (stdlib.h)
<cstring> (string.h)
C++11
<ctgmath> (tgmath.h)
<ctime> (time.h)
C++11
<cuchar> (uchar.h)
<cwchar> (wchar.h)
<cwctype> (wctype.h)
容器
C++11
<array>
<deque>
C++11
<forward_list>
<list>
<map>
<queue>
<set>
<stack>
C++11
<unordered_map>
C++11
<unordered_set>
<vector>
輸入/輸出
<fstream>
<iomanip>
<ios>
<iosfwd>
<iostream>
<istream>
<ostream>
<sstream>
<streambuf>
多執行緒
C++11
<atomic>
C++11
<condition_variable>
C++11
<future>
C++11
<mutex>
C++11
<thread>
其他
<algorithm>
<bitset>
C++11
<chrono>
C++11
<codecvt>
<complex>
<exception>
<functional>
C++11
<initializer_list>
<iterator>
<limits>
<locale>
<memory>
<new>
<numeric>
C++11
<random>
C++11
<ratio>
C++11
<regex>
<stdexcept>
<string>
C++11
<system_error>
C++11
<tuple>
C++11
<type_traits>
C++11
<typeindex>
<typeinfo>
<utility>
<valarray>
<unordered_set>
C++11
unordered_multiset
C++11
unordered_set
unordered_set
C++11
unordered_set::~unordered_set
C++11
unordered_set::unordered_set
成員函式
C++11
unordered_set::begin
C++11
unordered_set::bucket
C++11
unordered_set::bucket_count
C++11
unordered_set::bucket_size
C++11
unordered_set::cbegin
C++11
unordered_set::cend
C++11
unordered_set::clear
C++11
unordered_set::count
C++11
unordered_set::emplace
C++11
unordered_set::emplace_hint
C++11
unordered_set::empty
C++11
unordered_set::end
C++11
unordered_set::equal_range
C++11
unordered_set::erase
C++11
unordered_set::find
C++11
unordered_set::get_allocator
C++11
unordered_set::hash_function
C++11
unordered_set::insert
C++11
unordered_set::key_eq
C++11
unordered_set::load_factor
C++11
unordered_set::max_bucket_count
C++11
unordered_set::max_load_factor
C++11
unordered_set::max_size
C++11
unordered_set::operator=
C++11
unordered_set::rehash
C++11
unordered_set::reserve
C++11
unordered_set::size
C++11
unordered_set::swap
非成員過載
C++11
operators (unordered_set)
C++11
swap (unordered_set)
參考
<unordered_set>
unordered_set
emplace_hint
public member function
<unordered_set>
std::
unordered_set
::emplace_hint
template <class... Args>iterator emplace_hint ( const_iterator position, Args&&... args );
帶提示構建並插入元素
在 unordered_set 中插入一個新元素(如果其值是唯一的)。使用
args
作為元素建構函式的引數,在原地構造此新元素。
position
指向容器中的一個位置,該位置被建議作為搜尋插入點的提示(容器可能使用也可能不使用此建議來最佳化插入操作)。
只有當容器中不存在與要 emplaced 的值等價的元素時,插入才會發生(unordered_set 中的元素具有唯一的值)。
如果插入成功,容器的
size
將有效增加一。
存在一個類似的成員函式
insert
,它會複製或移動一個現有物件到容器中,並且也可以接受一個位置提示。
引數
position
作為插入操作的插入位置提示。該值可能被容器用來最佳化操作。
成員型別
const_iterator
是一個
forward iterator
型別。
args
傳遞給要插入的新元素的建構函式的引數。
返回值
如果插入成功(因為不存在具有相同值的其他元素),則函式返回指向已插入元素的迭代器。
否則,它返回一個指向容器中與該元素等價的元素的迭代器(該元素不會被替換)。
成員型別
iterator
是一個
forward iterator
型別。
unordered_set
中的所有迭代器都具有對元素的 const 訪問許可權:元素可以被插入或刪除,但不能在容器中被修改。
新元素的儲存使用
allocator_traits<allocator_type>::construct()
分配,這在失敗時可能會丟擲異常(對於預設的
allocator
,
bad_alloc
如果分配請求不成功,則丟擲)。
示例
還沒有示例。請參閱
unordered_set::emplace
的示例。
複雜度
平均情況:常量。
最壞情況:容器大小的線性。
可能會觸發
rehash
(未包含)。
迭代器有效性
在大多數情況下,插入後容器中的所有迭代器都保持有效。唯一的例外是當容器的增長強制重新雜湊時。在這種情況下,容器中的所有迭代器都將失效。
如果插入操作後新的容器
size
超過了其容量閾值(計算方法為容器的
bucket_count
乘以其
max_load_factor
),則會強制進行 rehash。
在所有情況下,即使在 rehash 之後,引用仍然保持有效。
另見
unordered_set::emplace
構造並插入元素
(公開成員函式)
unordered_set::insert
插入元素
(公開成員函式)