list empty() function in C++ STL

The list::empty() is a built-in function in C++ STL is used to check whether a particular list container is empty or not. This function does not modifies the list, it simply checks whether a list is empty or not, i.e. the size of list is zero or not.



Parameters: This function does not accept any parameter, it simply checks whether a list container is empty or not.

Return Value: The return type of this function is boolean. It returns True is the size of the list container is zero otherwise it returns False.

Below program illustrates the list::empty() function.





// CPP program to illustrate the
// list::empty() function
#include <bits/stdc++.h>
using namespace std;
int main()
    // Creating a list
    list<int> demoList;
    // check if list is empty
    if (demoList.empty())
        cout << "Empty List\n";
        cout << "Not Empty\n";
    // Add elements to the List
    // check again if list is empty
    if (demoList.empty())
        cout << "Empty List\n";
        cout << "Not Empty\n";
    return 0;



Empty List
Not Empty

Note: This function works in constant time complexity.

Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at to report any issue with the above content.