std::unordered_map<Key,T,Hash,KeyEqual,Allocator>::at
來自 cppreference.com
T& at( const Key& key ); |
(1) | (C++11 起) |
const T& at( const Key& key ) const; |
(2) | (C++11 起) |
template< class K > T& at( const K& x ); |
(3) | (C++26 起) |
template< class K > const T& at( const K& x ) const; |
(4) | (C++26 起) |
返回具有指定鍵的元素的對映值的引用。如果不存在此類元素,則丟擲 std::out_of_range 型別的異常。
1,2) 鍵等價於 key。
3,4) 鍵與值 x 比較等價。對映值的引用透過表示式 this->find(x)->second 獲取。
表示式 this->find(x) 必須是格式良好的並具有良好定義的行為,否則行為是未定義的。
這些過載僅在 Hash::is_transparent 和 KeyEqual::is_transparent 有效且每個都表示一個型別時才參與過載決議。這假定此類
Hash
可以與 K
和 Key
型別一起呼叫,並且 KeyEqual
是透明的,這共同允許在不構造 Key
例項的情況下呼叫此函式。目錄 |
[edit] 引數
key | - | 要查詢的元素的鍵 |
x | - | 可與鍵透明比較的任何型別的值 |
[edit] 返回值
對所請求元素的對映值的引用。
[edit] 異常
[edit] 複雜度
平均情況:常數時間,最壞情況:線性於大小。
注意
特性測試宏 | 值 | 標準 | 特性 |
---|---|---|---|
__cpp_lib_associative_heterogeneous_insertion |
202311L |
(C++26) | 有序和無序關聯容器中其餘成員函式的異構過載。(3,4) |
[edit] 示例
本節不完整 原因:無示例 |
[edit] 參閱
訪問或插入指定元素 (public member function) | |
查詢具有特定鍵的元素 (public member function) |