다음을 통해 공유


deque::deque

Constructs a deque of a specific size or with elements of a specific value or with a specific allocator or as a copy of all or part of some other deque.

deque( );
explicit deque(
   const Allocator& _Al
);
explicit deque(
   size_type _Count
);
deque(
   size_type _Count,
   const Type& _Val
);
deque(
   size_type _Count,
   const Type& _Val,
   const Allocator& _Al
);
deque(
   const deque& _Right
);
template<class InputIterator>
   deque(
      InputIterator _First,
      InputIterator _Last
   );
template<class InputIterator>
   deque(
      InputIterator _First,
      InputIterator _Last,
      const Allocator& _Al
   );

Parameters

  • _Al
    The allocator class to use with this object.

  • _Count
    The number of elements in the constructed deque.

  • _Val
    The value of the elements in the constructed deque.

  • _Right
    The deque of which the constructed deque is to be a copy.

  • _First
    Position of the first element in the range of elements to be copied.

  • _Last
    Position of the first element beyond the range of elements to be copied.

Remarks

All constructors store an allocator object (_Al) and initialize the deque.

The first two constructors specify an empty initial deque, the second specifying the allocator type (_Al) to be used.

The third constructor specifies a repetition of a specified number (_Count) of elements of the default value for class Type.

The fourth and fifth constructors specify a repetition of (_Count) elements of value _Val.

The sixth constructor specifies a copy of the deque _Right.

The last two constructors copy the range [_First, _Last) of a deque.

None of the constructors perform any interim reallocations.

Example

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

int main( ) 
{
   using namespace std;
   deque <int>::iterator c1_Iter, c2_Iter, c3_Iter, c4_Iter, c5_Iter, c6_Iter;

   // Create an empty deque c0
   deque <int> c0;

   // Create a deque c1 with 3 elements of default value 0
   deque <int> c1( 3 );

   // Create a deque c2 with 5 elements of value 2
   deque <int> c2( 5, 2 );

   // Create a deque c3 with 3 elements of value 1 and with the 
   // allocator of deque c2
   deque <int> c3( 3, 1, c2.get_allocator( ) );

   // Create a copy, deque c4, of deque c2
   deque <int> c4( c2 );

   // Create a deque c5 by copying the range c4[_First, _Last)
   c4_Iter = c4.begin( );
   c4_Iter++;
   c4_Iter++;
   deque <int> c5( c4.begin( ), c4_Iter );

   // Create a deque c6 by copying the range c4[_First, _Last) and 
   // c2 with the allocator of deque
   c4_Iter = c4.begin( );
   c4_Iter++;
   c4_Iter++;
   c4_Iter++;
   deque <int> c6( c4.begin( ), c4_Iter, c2.get_allocator( ) );

   cout << "c1 = ";
   for ( c1_Iter = c1.begin( ); c1_Iter != c1.end( ); c1_Iter++ )
      cout << *c1_Iter << " ";
   cout << endl;
   
   cout << "c2 = ";
   for ( c2_Iter = c2.begin( ); c2_Iter != c2.end( ); c2_Iter++ )
      cout << *c2_Iter << " ";
   cout << endl;

   cout << "c3 = ";
   for ( c3_Iter = c3.begin( ); c3_Iter != c3.end( ); c3_Iter++ )
      cout << *c3_Iter << " ";
   cout << endl;

   cout << "c4 = ";
   for ( c4_Iter = c4.begin( ); c4_Iter != c4.end( ); c4_Iter++ )
      cout << *c4_Iter << " ";
   cout << endl;

   cout << "c5 = ";
   for ( c5_Iter = c5.begin( ); c5_Iter != c5.end( ); c5_Iter++ )
      cout << *c5_Iter << " ";
   cout << endl;

   cout << "c6 = ";
   for ( c6_Iter = c6.begin( ); c6_Iter != c6.end( ); c6_Iter++ )
      cout << *c6_Iter << " ";
   cout << endl;
}

Output

c1 = 0 0 0 
c2 = 2 2 2 2 2 
c3 = 1 1 1 
c4 = 2 2 2 2 2 
c5 = 2 2 
c6 = 2 2 2 

Requirements

Header: <deque>

Namespace: std

See Also

Concepts

deque Class

deque Class Members

Standard Template Library