Reputation: 505
So, I want to use std::map
to find if an element exists. So I basically only need the key, not any value.
Is there any way to do something like std::map<std::string, void>
for example? Or is there a better alternative to std::map
for this kind of stuff?
Worst case scenario a different container like std::vector<std::string>
could be used, but I'm curious if you can do this with std::map
(std::map<std::string, bool>
could also be used, but the bools would be wasted memory).
Upvotes: 0
Views: 372
Reputation: 238311
Or is there a better alternative to std::map for this kind of stuff?
Yes. The container that you describe is a set. There are std::set
and std::unordered_set
corresponding to their map counterparts in the standard library.
Upvotes: 5