No, but with 2 elements, the std::unordered_set is gonna be slow, due to all the things that need to be done. If you have always just a couple of elements, just sticking them in a std::vector and doing a linear search might be much faster. You could also maintain an ordered list over a std::vector and use std::lower_bound for doing a binary search.