To get two types of access, you need to combine the two containers ... or reuse a library that combines the containers.
Boost.MultiIndex was invented for such needs.
The section provides an example in which there are employees available by ID (unique) and sorted by name (not unique), which is pretty much what you are going to do.
Key extractors may not be obvious. Suppose your thread is ressemble:
class Thread {
public:
std::size_t id() const;
std::size_t priority() const;
...
};
You should be able to write:
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index/const_mem_fun.hpp>
#include <boost/multi_index/member.hpp>
typedef multi_index_container<
Thread,
indexed_by<
ordered_unique<
const_mem_fun<Thread, std::size_t, &Thread::id>
>,
ordered_non_unique<
const_mem_fun<Thread, std::size_t, &Thread::priority>
>
>
> ThreadContainer;
Defines a stream container, uniquely identifying them id()and sorting according to them priority().
. , , , mem_fun const_mem_fun (, ).
( ) .