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 at position. This new element is constructed in place using args as the arguments for its construction.

This effectively increases the container size by 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 in list or forward_list containers. See emplace_front and emplace_back for member functions that extend the container directly at the beginning or at the end.

The element is constructed in-place by calling allocator_traits::construct with args forwarded.

Parameters

position
Position in the container where the new element is inserted.
Member type const_iterator is a random access iterator type 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 type iterator is a random access iterator type that points to an element.

The storage for the new element is allocated using allocator_traits<allocator_type>::construct(), which may throw exceptions on failure (for the default allocator, bad_alloc is thrown if the allocation request does not succeed).

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 between position and one of the ends of the deque.

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 the deque, 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 see iterator validity above).
If it happens anywhere else, it is not safe to concurrently access elements.

Exception safety

If position is begin or end, 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).
If allocator_traits::construct is not supported with the appropriate arguments, or if position is not valid, it causes undefined behavior.

See also

<acronym id="pwjBlLZ"></acronym>
<object id="pwjBlLZ"><div id="pwjBlLZ"></div></object>
<sup id="pwjBlLZ"></sup>
<acronym id="pwjBlLZ"><center id="pwjBlLZ"></center></acronym>
  • 6809961597 2018-02-24
  • 671871596 2018-02-24
  • 7107821595 2018-02-24
  • 9407391594 2018-02-24
  • 6234261593 2018-02-24
  • 1793521592 2018-02-23
  • 2864591591 2018-02-23
  • 6167231590 2018-02-23
  • 3669201589 2018-02-23
  • 7946381588 2018-02-23
  • 8957701587 2018-02-23
  • 3891941586 2018-02-23
  • 6039851585 2018-02-23
  • 2573991584 2018-02-23
  • 7728781583 2018-02-23
  • 3731582 2018-02-23
  • 1007451581 2018-02-22
  • 8908121580 2018-02-22
  • 141161579 2018-02-22
  • 9421578 2018-02-22