unordered_set end() in C++ STL Last Updated : 05 Jun, 2023 Comments Improve Suggest changes 4 Likes Like Report The unordered_set::end() function is a built-in function in C++ STL which returns an iterator pointing to the past-the-end-element. This iterator does not directly point to an element, rather it points to the location just after the last element. Syntax umap_name.end() or, umap_name.end(int i) Parameters: This function takes a single integer parameter i which is optional. Return value: If the parameter i is not passed then the function returns an iterator pointing to the past-the-end element. Actually, it does not point to any element of the set, but it points to the position following the last element of the container.If the parameter i is passed then the function returns an iterator pointing to the past-the-end element of i-th bucket. As in the previous case, it does not point to any element of the set, but it points to the position following the last element of i-th bucket. So the iterator returned by unordered_set::end() cannot be dereferenced. Below programs illustrate the unordered_set::end() function: Program 1: CPP // CPP program to illustrate the unordered_set::end() // function #include <iostream> #include <unordered_set> using namespace std; int main() { unordered_set<int> sampleSet = { 5, 10, 15, 4, 2, 7, 8, 6 }; // Continue the loop until it points to the // past-the-end position returned by sampleSet.end() for (auto it = sampleSet.begin(); it != sampleSet.end(); it++) { cout << *it << " "; } return 0; } Output:6 8 7 2 4 15 10 5 Time Complexity: O(1) Auxiliary Space: O(1) Program 2: CPP // CPP program to illustrate the // unordered_set::end() function #include <iostream> #include <unordered_set> using namespace std; int main() { unordered_set<int> sampleSet = { 5, 10, 15, 4, 2, 7, 8, 6 }; // displaying all the buckets of the set. // Continue the loop until it points to the // past-the-end position returned by sampleset.end(i) for (unsigned i = 0; i < sampleSet.bucket_count(); ++i) { cout << "Bucket " << i << " Contains: "; for (auto it1 = sampleSet.begin(i); it1 != sampleSet.end(i); ++it1) cout << " " << *it1; cout << endl; } return 0; } Output:Bucket 0 Contains: Bucket 1 Contains: Bucket 2 Contains: 2 Bucket 3 Contains: Bucket 4 Contains: 4 15 Bucket 5 Contains: 5 Bucket 6 Contains: 6 Bucket 7 Contains: 7 Bucket 8 Contains: 8 Bucket 9 Contains: Bucket 10 Contains: 10 Time Complexity: O(1) Auxiliary Space: O(1) Comment T tufan_gupta2000 Follow 4 Improve T tufan_gupta2000 Follow 4 Improve Article Tags : C++ CPP-Functions cpp-unordered_set cpp-unordered_set-functions Explore C++ BasicsIntroduction to C++3 min readData Types in C++6 min readVariables in C++4 min readOperators in C++9 min readBasic Input / Output in C++3 min readControl flow statements in Programming15+ min readLoops in C++7 min readFunctions in C++8 min readArrays in C++8 min readCore ConceptsPointers and References in C++5 min readnew and delete Operators in C++ For Dynamic Memory5 min readTemplates in C++8 min readStructures, Unions and Enumerations in C++3 min readException Handling in C++12 min readFile Handling in C++8 min readMultithreading in C++8 min readNamespace in C++5 min readOOP in C++Object Oriented Programming in C++8 min readInheritance in C++6 min readPolymorphism in C++5 min readEncapsulation in C++3 min readAbstraction in C++4 min readStandard Template Library(STL)Standard Template Library (STL) in C++3 min readContainers in C++ STL2 min readIterators in C++ STL10 min readC++ STL Algorithm Library3 min readPractice & ProblemsC++ Interview Questions and Answers1 min readC++ Programming Examples4 min read Like