Compartilhar via


deque::push_front

Adds an element to the beginning of the deque.

void push_front(
   const Type& _Val
);
void push_front(
   Type&& _Val
);

Parameters

Parameter

Description

_Val

The element added to the beginning of the deque.

Remarks

If an exception is thrown, the deque is left unaltered and the exception is rethrown.

Example

// deque_push_front.cpp
// compile with: /EHsc
#include <deque>
#include <iostream>
#include <string>

int main( ) 
{
   using namespace std;
   deque <int> c1;
   
   c1.push_front( 1 );
   if ( c1.size( ) != 0 )
      cout << "First element: " << c1.front( ) << endl;

   c1.push_front( 2 );
   if ( c1.size( ) != 0 )
      cout << "New first element: " << c1.front( ) << endl;

// move initialize a deque of strings
   deque <string> c2;
   string str("a");

   c2.push_front( move( str ) );
   cout << "Moved first element: " << c2.front( ) << endl;
}
First element: 1
New first element: 2
Moved first element: a

Requirements

Header: <deque>

Namespace: std

See Also

Reference

deque Class

deque::push_front and deque::pop_front

Standard Template Library

Other Resources

deque Class Members