unordered_set cend() function in C++ STL Last Updated : 05 Jun, 2023 Comments Improve Suggest changes Like Article Like Report The unordered_set::cend() method is a built-in function in C++ STL which is used to return a const_iterator pointing to past-the-end element in the unordered_set container or in one of it's bucket. This function does not directly point to any element in the container. It is only used to denote the end of a container or the open end of a range as in [cbegin, cend). Note: A const_iterator can only be used to access elements, it cannot modify the elements present in the container. Syntax: unordered_set_name.cend(n); Parameter: This function accepts a single parameter n. This is an optional parameter and specifies the bucket number. If this parameter is not passed then the cend() method will return a const_iterator pointing to the position just after the last element of the container and if this parameter is passed then the cend() method will return a const_iterator pointing to the position just after the last element in a specific bucket in the unordered_set container. Return Value: This function returns a const_iterator pointing to the position just after the last element in the container or a specified bucket in the container. Below programs illustrate the unordered_set::cend() function: Program 1: CPP // C++ program to illustrate the // unordered_set::cend() function #include <iostream> #include <unordered_set> using namespace std; int main() { unordered_set<int> sampleSet; // Inserting elements in the std sampleSet.insert(5); sampleSet.insert(10); sampleSet.insert(15); sampleSet.insert(20); sampleSet.insert(25); // Here, the cend() method is used to // iterate in the range of elements // present in the unordered_set container cout << "Elements present in sampleSet are: \n"; for (auto itr = sampleSet.cbegin(); itr != sampleSet.cend(); itr++) { cout << *itr << endl; } return 0; } Output:Elements present in sampleSet are: 25 5 10 15 20 Program 2: CPP // C++ program to illustrate the // unordered_set::cend() function #include <iostream> #include <unordered_set> using namespace std; int main() { unordered_set<string> sampleSet; // Inserting elements sampleSet.insert("Welcome"); sampleSet.insert("To"); sampleSet.insert("GeeksforGeeks"); sampleSet.insert("Computer Science Portal"); sampleSet.insert("For Geeks"); // Here, the cend() method is used to // iterate in the range of elements // present in the unordered_set container cout << "Elements present in sampleSet are: \n"; for (auto itr = sampleSet.cbegin(); itr != sampleSet.cend(); itr++) { cout << *itr << endl; } return 0; } Output:Elements present in sampleSet are: Welcome To GeeksforGeeks For Geeks Computer Science Portal Time complexity: O(1) Comment More infoAdvertise with us Next Article unordered_multiset cend() function in C++ STL B barykrg Follow Improve Article Tags : Misc C++ CPP-Functions cpp-unordered_set cpp-unordered_set-functions +1 More Practice Tags : CPPMisc Similar Reads unordered_set cbegin() function in C++ STL The unordered_set::cbegin() method is a built-in function in C++ STL which is used to return a const_iterator pointing to the first element in the unordered_set container. This iterator can point to either the very the first element or first element of any specified bucket in the unordered_set conta 2 min read unordered_multiset cend() function in C++ STL The unordered_multiset::cend() is a built-in function in C++ STL which returns a constant iterator pointing to the position immediately after the last element in the container or to the position immediately after the last element in one of its bucket. Syntax: unordered_multiset_name.cend(n) Paramete 2 min read unordered_set clear() function in C++ STL 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 redu 2 min read unordered_set count() function in C++ STL The unordered_set::count() function is a built-in function in C++ STL which is used to count occurrences of a particular element in an unordered_set container. As the unordered_set container does not allows to store duplicate elements so this function is generally used to check if an element is pres 2 min read unordered_multiset end() function in C++ STL The unordered_multiset::end() is a built-in function in C++ STL which returns an iterator pointing to the position immediately after the last element in the container or to the position immediately after the last element in one of its bucket. Syntax: unordered_multiset_name.end(n) Parameters: The fu 2 min read unordered_set emplace() function in C++ STL The unordered_set::emplace() function is a built-in function in C++ STL which is used to insert an element in an unordered_set container. The element is inserted only if it is not already present in the container. This insertion also effectively increases the container size 1.Syntax: unordered_set_n 2 min read Like