原文地址:http://www.cplusplus.com/reference/deque/deque/emplace/
public member function
<deque>
std::deque::emplace
template <class... Args>
iterator emplace (const_iterator position, Args&&... args);
Construct and insert element
The container is extended by inserting a new element atposition. This new element is constructed in place usingargsas the arguments for its construction.
通过在指定位置插入一个新的元素以扩展容器,新的元素的值使用参数args传递给元素的构造器构造。
This effectively increases the containersizeby one.
这是一种高效的增加容器大小的方法。
Double-ended queues are designed to be efficient performing insertions (and removals) from either the end or the beginning of the sequence. Insertions on other positions are usually less efficient than inlistorforward_listcontainers.
Seeemplace_frontandemplace_backfor
member functions that extend the container directly at the beginning or at the end.
双端队列设计是为了能高效地在开头以及结尾插入以及删除元素的序列,在其他位置插入元素通常表现比list以及forward_list更差。
The element is constructed in-place by callingallocator_traits::constructwithargsforwarded.
Parameters
position
Position in the container where the new element is inserted.
Member typeconst_iteratoris arandom access iteratortype that points to a constant element.
新元素插入的位置。
args
Arguments forwarded to construct the new element.
构造新元素的参数。
Return value
An iterator that points to the newly emplaced element.
返回插入新元素的迭代器。
Member typeiteratoris arandom access iteratortype that points to an element.
迭代器属于随机访问迭代器。
The storage for the new element is allocated usingallocator_traits<allocator_type>::construct(), which may throw exceptions on failure (for the defaultallocator,bad_allocis
thrown if the allocation request does not succeed).
如果发生了重分配,将使用容器的分配器进行内存分配,这可能会抛出异常。(例如allocator这个默认的分配器在请求失败时会抛出bad_alloc异常)
Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
// deque::emplace
#include <iostream>
#include <deque>
int main ()
{
std::deque<int> mydeque = {10,20,30};
auto it = mydeque.emplace ( mydeque.begin()+1, 100 );
mydeque.emplace ( it, 200 );
mydeque.emplace ( mydeque.end(), 300 );
std::cout << "mydeque contains:";
for (auto& x: mydeque)
std::cout << ' ' << x;
std::cout << '\n';
return 0;
}
|
|
Output:
mydeque contains: 10 200 100 20 30 300
|
Complexity
Depending on the particular library implemention, up to linear in the number of elements betweenpositionand one of the ends of thedeque.
Iterator validity
If the insertion happens at the beginning or the end of the sequence, all iterators related to this container are invalidated, but pointers and references remain valid, referring to the same elements they were referring to before
the call.
If the insertion happens anywhere else in thedeque, all iterators, pointers and references related to this container
are invalidated.
Data races
The container is modified.
If the insertion happens at the beginning or the end of the sequence, no contained elements are accessed (although seeiterator validityabove).
If it happens anywhere else, it is not safe to concurrently access elements.
Exception safety
Ifpositionisbeginorend,
there are no changes in the container in case of exception (strong guarantee).
Otherwise, the container is guaranteed to end in a valid state (basic guarantee).
Ifallocator_traits::constructis not supported with the appropriate arguments, or ifpositionis not valid, it causesundefined
behavior.
——————————————————————————————————————————————————————————————————
//翻译的不好的地方请多多指导,可以在下面留言或者点击左上方邮件地址给我发邮件,指出我的错误以及不足,以便我修改,更好的分享给大家,谢谢。
//今后的翻译将以简洁为主,翻译其主要意思,一些重复率太高的也将不再翻译,只翻译重要的部分。
转载请注明出处:http://blog.csdn.net/qq844352155
author:天下无双
Email:coderguang@gmail.com
2014-9-1
于GDUT
——————————————————————————————————————————————————————————————————
分享到:
相关推荐
STL的容器deque的详细使用方法和文档 6.0代码
SGI STL deque相关代码
本文深入地研究了std::deque 容器。本文将讨论在一些情况下使用deque> 比vector更好。读完这篇文章后读者应该能够理解在容量增长...由于deque> 和vector的用法很相似,读者可以参考vector 文档中介绍如何使用STL容器。
poj1113 melkman算法求凸包, 使用STL
STL中的deque模板包括迭代器等接口
C++实现STL容器之deque
vector和deque使用方法
Introduction to STL.doc STL vector 容器介绍.doc Visual+C调试功能.doc 三十分钟掌握STL.doc 深入研究 STL Deque 容器.doc 深入研究 STL Deque 容器.pdf
这个实例介绍了每种STL容器的使用,包括Map/Vector/List/Queque/Set/MultiMap和各种STL算法的使用。供初学者参考使用
STL中vector、list、deque和map的区别
案例-评委打分 ...遍历vector容器,取出来每一个选手,执行for循环,可以把10个评分打分存到deque容器中 sort算法对deque容器中分数排序,去除最高和最低分 deque容器遍历一遍,累加总分 获取平均分
STL 是“Standard Template Library”的缩写,中文译为“标准模板库”。...例如,vector 的底层为顺序表(数组),list 的底层为双向链表,deque 的底层为循环队列,set 的底层为红黑树,hash_set 的底层为哈希表。
STL入门 STL入门 STL入门 STL入门 STL入门 STL入门
STL格式模型文件STL格式模型文件STL格式模型文件STL格式模型文件STL格式模型文件STL格式模型文件STL格式模型文件STL格式模型文件STL格式模型文件STL格式模型文件STL格式模型文件STL格式模型文件STL格式模型文件STL...
快速掌握STL的教程,希望能帮到大家,个人觉得很有用,希望对那些初学者有用
stl转换,能够有效的将matlab 转化为stl文件,用于3DMAX的绘图
详细解说STL 详细解说STL 详细解说STL 详细解说STL
用于STL文件读取与显示的C语言程序,简单方便实用。
常用STL的简单使用方法: /队列的使用 /链表的使用 /容器 vector 的使用
走进STL走进STL走进STL走进STL走进STL走进STL走进STL走进STL