public member function
<deque>

std::deque::push_back

void push_back (const value_type& val);
void push_back (const value_type& val);
void push_back (value_type&& val);
Add element at the end
Adds a new element at the end of the deque container, after its current last element. The content of val is copied (or moved) to the new element.

This effectively increases the container size by one.

Parameters

val
Value to be copied (or moved) to the new element.
Member type value_type is the type of the elements in the container, defined in deque as an alias of its first template parameter (T).

Return value

none

The storage for the new elements is allocated using the container's allocator, 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
20
// deque::push_back
#include <iostream>
#include <deque>

int main ()
{
  std::deque<int> mydeque;
  int myint;

  std::cout << "Please enter some integers (enter 0 to end):\n";

  do {
    std::cin >> myint;
    mydeque.push_back (myint);
  } while (myint);

  std::cout << "mydeque stores " << (int) mydeque.size() << " numbers.\n";

  return 0;
}

The example uses push_back to add a new element to the container each time a new integer is read.

Complexity

Constant.

Iterator validity

All iterators related to this container are invalidated. Pointers and references to elements in the container remain valid, referring to the same elements they were referring to before the call.

Data races

The container is modified.
No existing elements are accessed (although see iterator validity above).

Exception safety

Strong guarantee: if an exception is thrown, there are no changes in the container.
If allocator_traits::construct is not supported with val as argument, 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