unordered_set hash_function() in C++ STL Last Updated : 05 Jun, 2023 Comments Improve Suggest changes 15 Likes Like Report The unordered_set::hash_function() is a built-in function in C++ STL which is used to get hash function. This hash function is a unary function which takes asingle argument only and returns a unique value of type size_t based on it. Syntax: unordered_set_name.hash_function() Parameter: The function accepts no parameter. Return Value: The function returns the hash function. Below programs illustrate the unordered_set::hash_function() function: Program 1: CPP // CPP program to illustrate the // unordered_set::hash() function #include <iostream> #include <string> #include <unordered_set> using namespace std; int main() { unordered_set<string> sampleSet = { "geeks1", "for", "geeks2" }; // use of hash_function unordered_set<string>::hasher fn = sampleSet.hash_function(); cout << fn("geeks") << endl; for (auto it = sampleSet.begin(); it != sampleSet.end(); it++) { cout << *it << " "; } cout << endl; return 0; } Output:15276750567035005396 geeks2 geeks1 for Program 2: CPP // CPP program to illustrate the // unordered_set::hash() function #include <iostream> #include <string> #include <unordered_set> using namespace std; int main() { unordered_set<string> sampleSet; // use of hash_function unordered_set<string>::hasher fn = sampleSet.hash_function(); cout << fn("geeksforgeeks") << endl; return 0; } Output:5146686323530302118 Time complexity: O(1) Create Quiz Comment B barykrg Follow 15 Improve B barykrg Follow 15 Improve Article Tags : Misc C++ CPP-Functions cpp-unordered_set cpp-unordered_set-functions +1 More 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