Short answer
Yes. In C#, HashSet<T> is in the System.Collections.Generic namespace. C++ has no class with that name. The C++ equivalent is std::unordered_set, from the <unordered_set> header. The C language has no hash set at all.
This page is about C++, so the C# code below is here only for comparison.
HashSet in C#
A short C# example:
using System.Collections.Generic;
var colors = new HashSet<string>();
colors.Add("red");
colors.Add("green");
bool addedAgain = colors.Add("red"); // false, red is already in the set
bool hasGreen = colors.Contains("green"); // true
Add returns true when the item was added and false when it was already there. Contains checks whether an item is present.
The C++ equivalent
Here are the same steps in C++:
#include <iostream>
#include <string>
#include <unordered_set>
int main() {
std::unordered_set<std::string> colors;
colors.insert("red");
colors.insert("green");
colors.insert("red"); // ignored, red is already in the set
bool has_green = colors.find("green") != colors.end();
std::cout << std::boolalpha << has_green << "\n"; // prints true
return 0;
}
insert() plays the role of Add, and find() compared with end() plays the role of Contains. insert() returns a pair, and its second member tells you whether the value was added.
Name mapping
The names differ between languages, but the ideas line up:
| C# | C++ | What it holds |
|---|---|---|
HashSet<T> |
std::unordered_set<T> |
Unique items, no guaranteed order |
Dictionary<TKey, TValue> |
std::unordered_map<K, V> |
Key-value pairs, no guaranteed order |
SortedSet<T> |
std::set<T> |
Unique items, kept in sorted order |
C++ has no class named HashSet, so when you read C++ code, look for std::unordered_set instead.
What about C?
The C standard library has no hash set and no set type. If you are writing C and need one, you would write your own hash table or use a third-party library. C++ includes std::unordered_set in its standard library, so you do not need to write one yourself.
Where to go next
If you are learning C++ and want the full walkthrough of the C++ type, read about hashset in c. It covers creating, checking, removing and looping, along with common mistakes.