The unordered_set::clear() function is a built-in function in C++ STL which is used to clear an unordered_set container. That is, this function removes all of the elements from an unordered_set and empties it. All of the iterators, pointers, and references to the container are invalidated. This reduces the size of the container to zero.
Parameter: This function does not accepts any parameter.
Return Value: This function does not returns any value.
Below programs illustrate the unordered_set::clear() function:
sampleSet contains: 25 5 10 15 20 Size of set after clearing elemets: 0
sampleSet contains: Welcome To GeeksforGeeks For Geeks Computer Science Portal Size of set after clearing elemets: 0
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.
- multimap clear() function in C++ STL
- ios clear() function in C++ with Examples
- unordered_multimap clear() function in C++ STL
- multiset clear() function in C++ STL
- unordered_multiset clear() function in C++ STL
- set::clear in C++ STL
- map::clear() in C++ STL
- std::string::clear in C++
- list::clear() in C++ STL
- unordered_map clear in C++ STL
- vector erase() and clear() in C++
- Different ways to delete elements in std::map (erase() and clear())
- forward_list::clear() and forward_list::erase_after() in C++ STL
- deque::clear() and deque::erase() in C++ STL
- Difference between user defined function and library function in C/C++
- Function Overloading vs Function Overriding in C++
- How to call some function before main() function in C++?
- How to call function within function in C or C++
- Difference between Virtual function and Pure virtual function in C++
- What happens when a virtual function is called inside a non-virtual function in C++
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.