Note that there is also flat_set / flat_map in the boost containers library, which does exactly that.
From: Boost-users <boost-users-bounces@lists.boost.org> on behalf of degski via Boost-users <boost-users@lists.boost.org> Sent: Friday, July 14, 2017 12:51:53 PM To: boost-users@lists.boost.org Cc: degski Subject: Re: [Boost-users] boost::unordered_map takes too long when I have only two elements in it
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.