unordered_set equal_range in C++ STL Last Updated : 11 Jul, 2025 Comments Improve Suggest changes 2 Likes Like Report equal_range() in general returns range that includes all elements equal to given value. For unordered_set where all keys are distinct, the returned range contains at-most one element. Syntax setname.equal_range(key name) Arguments It takes the key to be searched as parameter. Return Value It returns two iteraters---- lower and upper bound of the range that contains the key. Example CPP // C++ program to illustrate the // unordered_set::equal_range function #include <iostream> #include <unordered_set> using namespace std; int main() { // declaration unordered_set<int> sample; // Insert some values sample.insert({ 20, 30, 40 }); // Test the equal_range function for // a given key if it does exists auto range1 = sample.equal_range(20); if (range1.first != sample.end()) { for (; range1.first != range1.second; ++range1.first) cout << *range1.first << endl; } else cout << "Element does not exist"; return 0; } Output 20 CPP // C++ program to illustrate the // unordered_set::equal_range function #include <iostream> #include <unordered_set> using namespace std; int main() { // declaration unordered_set<int> sample; // Insert some values sample.insert({ 20, 30, 40 }); // Test the equal_range function // for a given key if it does not exist auto range1 = sample.equal_range(60); if (range1.first != sample.end()) { for (; range1.first != range1.second; ++range1.first) cout << *range1.first << endl; } else cout << "Element does not exist"; return 0; } Output Element does not exist Time complexity: O(n) Comment T tufan_gupta2000 Follow 2 Improve T tufan_gupta2000 Follow 2 Improve Article Tags : C++ 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