public member function
size_type max_size () const;
Return maximum size
Returns the maximum number of elements that the
vector container can hold.
This is not the amount of storage space currently allocated to the vector (this can be obtained with member
vector::capacity), but the maximum potential size the vector could reach due to system or library implementation limitations.
Parameters
none
Return Value
The maximum number of elements a
vector object can have as its content.
Member type
size_type is an unsigned integral type.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
// comparing size, capacity and max_size
#include <iostream>
#include <vector>
using namespace std;
int main ()
{
vector<int> myvector;
// set some content in the vector:
for (int i=0; i<100; i++) myvector.push_back(i);
cout << "size: " << myvector.size() << "\n";
cout << "capacity: " << myvector.capacity() << "\n";
cout << "max_size: " << myvector.max_size() << "\n";
return 0;
}
|
A possible output for this program could be:
size: 100
capacity: 141
max_size: 1073741823
|
Complexity
Constant.
See also
- vector::capacity
- Return size of allocated storage capacity (public member function)
- vector::size
- Return size (public member function)
- vector::resize
- Change size (public member function)