deque::resize (STL/CLR)

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at deque::resize (STL/CLR).

Changes the number of elements.

Syntax

void resize(size_type new_size);  
void resize(size_type new_size, value_type val);  

Parameters

new_size
New size of the controlled sequence.

val
Value of the padding element.

Remarks

The member functions both ensure that deque::size (STL/CLR)() henceforth returns new_size. If it must make the controlled sequence longer, the first member function appends elements with value value_type(), while the second member function appends elements with value val. To make the controlled sequence shorter, both member functions effectively erase the last element deque::size (STL/CLR)() - new_size times. You use it to ensure that the controlled sequence has size new_size, by either trimming or padding the current controlled sequence.

Example

// cliext_deque_resize.cpp   
// compile with: /clr   
#include <cliext/deque>   
  
int main()   
    {   
// construct an empty container and pad with default values   
    cliext::deque<wchar_t> c1;   
    System::Console::WriteLine("size() = {0}", c1.size());   
    c1.resize(4);   
    for each (wchar_t elem in c1)   
        System::Console::Write(" {0}", (int)elem);   
    System::Console::WriteLine();   
  
// resize to empty   
    c1.resize(0);   
    System::Console::WriteLine("size() = {0}", c1.size());   
  
// resize and pad   
    c1.resize(5, L'x');   
    for each (wchar_t elem in c1)   
        System::Console::Write(" {0}", elem);   
    System::Console::WriteLine();   
    return (0);   
    }  
  
size() = 0  
 0 0 0 0  
size() = 0  
 x x x x x  

Requirements

Header: <cliext/deque>

Namespace: cliext

See Also

deque (STL/CLR)
deque::clear (STL/CLR)
deque::erase (STL/CLR)
deque::insert (STL/CLR)