vector::capacity (STL/CLR)
Reports the size of allocated storage for the container.
size_type capacity();
Remarks
The member function returns the storage currently allocated to hold the controlled sequence, a value at least as large as vector::size (STL/CLR)(). You use it to determine how much the container can grow before it must reallocate storage for the controlled sequence.
Example
// cliext_vector_capacity.cpp
// compile with: /clr
#include <cliext/vector>
int main()
{
cliext::vector<wchar_t> c1;
c1.push_back(L'a');
c1.push_back(L'b');
c1.push_back(L'c');
// display initial contents " a b c"
for (int i = 0; i < c1.size(); ++i)
System::Console::Write(" {0}", c1.at(i));
System::Console::WriteLine();
// increase capacity
cliext::vector<wchar_t>::size_type cap = c1.capacity();
System::Console::WriteLine("capacity() = {0}, ok = {1}",
cap, c1.size() <= cap);
c1.reserve(cap + 5);
System::Console::WriteLine("capacity() = {0}, ok = {1}",
c1.capacity(), cap + 5 <= c1.capacity());
return (0);
}
a b c
capacity() = 4, ok = True
capacity() = 9, ok = True
Description
Note that the actual capacities may differ from the values shown here, so long as all ok tests report true.
Requirements
Header: <cliext/vector>
Namespace: cliext