std::unordered_map::insert_or_assign
STD:无序[医]地图::插入[医]或[医]指派
template | (1) | (since C++17) |
---|---|---|
template <class M> pair<iterator, bool> insert_or_assign(key_type&& k, M&& obj | (2) | (since C++17) |
template <class M> iterator insert_or_assign(const_iterator hint, const key_type& k, M&& obj | (3) | (since C++17) |
template <class M> iterator insert_or_assign(const_iterator hint, key_type&& k, M&& obj | (4) | (since C++17) |
1,3%29,如果密钥相当于k已存在于容器中,则分配std::forward<M>(obj)到mapped_type对应键k如果键不存在,则插入新值,就像插入,从value_type(k,std::forward<M>(obj))
2,4%29与%281,3%29相同,但映射值是从value_type(std::move(k),std::forward<M>(obj))
如果由于插入而发生重散列,则所有迭代器都将失效。否则迭代器不会受到影响。引用不失效。只有当新元素数大于max_load_factor()*bucket_count()
如果插入成功,则在节点句柄中保存时获得的元素的指针和引用无效,并且在提取该元素之前获得的指针和引用变得有效。%28自C++17%29。
参数
k | - | the key used both to look up and to insert if not found |
---|---|---|
hint | - | iterator to the position before which the new element will be inserted |
args | - | arguments to forward to the constructor of the element |
返回值
1,2%29 bool组分是true
如果插入发生了false
如果任务发生了。迭代器组件指向插入或更新的元素。
3,4%29指向插入或更新的元素的Iterator
复杂性
1,2%29与座落
3.4%29与座落[医]暗示
注记
insert_or_assign
返回比operator[]
并且不要求映射类型的默认可构造性。
例
另见
operator[] | access specified element (public member function) |
---|---|
at | access specified element with bounds checking (public member function) |
insert | inserts elements or nodes (since C++17) (public member function) |
emplace | constructs element in-place (public member function) |
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
http://en.cppreference.com/w/cpp/container/unorder[医]地图/插入[医]或[医]指派