std::map 是一種有序關聯容器,它包含具有唯一鍵的鍵值對。鍵之間以比較函數 Compare 排序。搜索、移除和插入操作擁有對數複雜度。map 通常實現為紅黑樹。 std::map 的迭代器以升序迭代各鍵,此升序由構造時所用的比較函數定義。就是說,給定 m,一個 std::map it_l 和it_r,m 的可解引用迭代器,且 it...
std::map<Key,T,Compare,Allocator>::emplace C++ Containers library std::map template<class...Args> std::pair<iterator,bool>emplace(Args&&...args); (since C++11) (constexpr since C++26) Inserts a new element into the container constructed in-place with the givenargs, if there is no elem...
以与提供给 emplace 严格相同的实参,通过 std::forward<Args>(args)... 转发,调用新元素(即 std::pair<const Key, T>)的构造函数。即使容器中已有拥有该关键的元素,也可能构造元素,该情况下新构造的元素将被立即销毁(若不想要此行为,请参见 try_emplace())。
std::unordered_map template<class...Args> std::pair<iterator,bool>emplace(Args&&...args); (since C++11) Inserts a new element into the container constructed in-place with the givenargs, if there is no element with the key in the container. ...
unordered_map(C++11) unordered_multimap(C++11) unordered_set(C++11) unordered_multiset(C++11) Container adaptors span(C++20)−mdspan(C++23) Iterators library Ranges library(C++20) Range factories−Range adaptors generator(C++23) Algorithms library ...
以与提供给 emplace 严格相同的实参,通过 std::forward<Args>(args)... 转发,调用新元素(即 std::pair<const Key, T>)的构造函数。即使容器中已有拥有该关键的元素,也可能构造元素,该情况下新构造的元素将被立即销毁(若不想要此行为,请参见 try_emplace())。
std::map<Key,T,Compare,Allocator>::try_emplace C++ Containers library std::map template<class...Args> std::pair<iterator,bool>try_emplace(constKey&k, Args&&...args); (1)(since C++17) template<class...Args> std::pair<iterator,bool>try_emplace(Key&&k, Args&&...args); ...
(const map<Key, T, Compare, Allocator>& x, const map<Key, T, Compare, Allocator>& y); template<class Key, class T, class Compare, class Allocator> /*synth-three-way-result*/<pair<const Key, T>> operator<=>( const map<Key, T, Compare, Allocator>& x, const map<Key, T, ...
map::erase map::swap map::extract (C++17) map::merge (C++17) map::insert_range (C++23) map::insert_or_assign (C++17) map::emplace (C++11) map::emplace_hint (C++11) map::try_emplace (C++17) Lookup map::count map::find map::contains (C++20) map::equal_range map::lower_bo...
emplace_hint(it, i, 'b'); it = map.end(); } return map.size(); } std::size_t map_emplace_hint_wrong() { std::map<int, char> map; auto it = map.begin(); for (int i = n_operations; i > 0; --i) { map.emplace_hint(it, i, 'c'); it = map.end(); } return ...