首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::multiset::insert

iterator insert( const value_type& value );

(1)

iterator insert( value_type&& value );

(2)

(since C++11)

(3)

iterator insert( iterator hint, const value_type& value );

(until C++11)

iterator insert( const_iterator hint, const value_type& value );

(since C++11)

iterator insert( const_iterator hint, value_type&& value );

(4)

(since C++11)

template< class InputIt > void insert( InputIt first, InputIt last );

(5)

void insert( std::initializer_list<value_type> ilist );

(6)

(since C++11)

iterator insert(node_type&& nh);

(7)

(since C++17)

iterator insert(const_iterator hint, node_type&& nh);

(8)

(since C++17)

将元素%28S%29插入容器中。

1-2%29次插入value如果容器具有具有等效键的元素,则从C++11%29开始在该范围的上限处插入.%28。

3-4%29次插入value在尽可能接近的位置上,从C++11%29开始,刚好在%28之前hint...

5%29插入范围内的元素[first, last)...

6%29从初始化程序列表插入元素ilist...

7%29nh是空的节点手柄什么都不做。否则,插入nh并返回指向插入元素的迭代器。如果包含具有等价键的元素的范围nh.key()存在于容器中,则元素插入到该范围的末尾。如果nh不是空的get_allocator() != nh.get_allocator()...

8%29nh是空的节点手柄,什么也不做,并返回结束迭代器。否则,插入nh,并返回指向元素的迭代器,该元素的键等价于nh.key()元素插入的位置尽可能靠近hint如果nh不是空的get_allocator() != nh.get_allocator()...

没有迭代器或引用无效。如果插入成功,则在节点句柄中保存时获得的元素的指针和引用无效,并且在提取该元素之前获得的指针和引用变得有效。%28自C++17%29。

参数

hint

-

iterator, used as a suggestion as to where to start the search (until C++11) iterator to the position before which the new element will be inserted (since C++11)

iterator, used as a suggestion as to where to start the search

(until C++11)

iterator to the position before which the new element will be inserted

(since C++11)

iterator, used as a suggestion as to where to start the search

(until C++11)

iterator to the position before which the new element will be inserted

(since C++11)

value

-

element value to insert

first, last

-

range of elements to insert

ilist

-

initializer list to insert the values from

nh

-

a compatible node handle

类型要求

-输入必须符合输入器的要求。

返回值

1-4%29向插入元素返回迭代器。

5-6%29%280%29

7,8%29末端迭代器nh为空,否则迭代器指向插入的元素。

例外

1-4%29如果任何操作引发异常,则插入无效。

复杂性

容器大小为1-2%29对数,O(log(size()))...

3-4) Amortized constant if the insertion happens in the position just after the hint, logarithmic in the size of the container otherwise.

(until C++11)

3-4) Amortized constant if the insertion happens in the position just before the hint, logarithmic in the size of the container otherwise.

(since C++11)

5-6%29O(N*log(size() + N)),其中N是要插入的元素数。

容器大小为7%29对数,O(log(size()))...

8%29摊销常数,如果插入发生在刚才的位置以前提示,否则为容器大小的对数。

另见

emplace (C++11)

constructs element in-place (public member function)

emplace_hint (C++11)

constructs elements in-place using a hint (public member function)

代码语言:txt
复制
 © cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券