The forward_list::max_size() is a built-in function in C++ STL which returns the maximum number of elements a forward_list container can hold
Syntax:
forward_list_name.max_size()
Parameters: The function does not accept any parameters.
Return Value: The function returns the maximum number of elements the container can hold.
Below programs illustrate the above function:
Program 1:
#include <bits/stdc++.h>
using namespace std;
int main()
{
forward_list< int > fl;
fl.assign(5, 8);
cout << "The forward_list elements: " ;
for ( auto it = fl.begin(); it != fl.end(); it++)
cout << *it << " " ;
cout << "\nThe max size: " << fl.max_size();
return 0;
}
|
Output:
The forward_list elements: 8 8 8 8 8
The max size: 1152921504606846975
Program 1:
#include <bits/stdc++.h>
using namespace std;
int main()
{
forward_list< int > fl;
cout << "\nThe max size: " << fl.max_size();
return 0;
}
|
Output:
The max size: 1152921504606846975
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
23 Jul, 2018
Like Article
Save Article