Open In App

forward_list max_size() in C++ STL with Examples

Last Updated : 23 Jul, 2018
Comments
Improve
Suggest changes
Like Article
Like
Report
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: CPP
// CPP program to demonstrate the
// forward_list::max_size() function
// when the list is not-empty
#include <bits/stdc++.h>
using namespace std;
int main()
{
    // declaration of forward list
    forward_list<int> fl;

    // assign value
    fl.assign(5, 8);

    // prints the elements
    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: CPP
// CPP program to demonstrate the
// forward_list::max_size() function
// when the list is empty
#include <bits/stdc++.h>
using namespace std;
int main()
{
    // declaration of forward list
    forward_list<int> fl;

    cout << "\nThe max size: " << fl.max_size();
    return 0;
}
Output:
The max size: 1152921504606846975

Next Article
Practice Tags :

Similar Reads