I have a std::unordered_set
of elements of type T
, and a function U key_of(const T& t)
. Now, I want to have a C++ construct which:
- supports some of
std::unordered_map
's methods; at the very least: operator[] const, find, and the iterators. - does not incur the storage of actually building the map (not even with T*s)
- is backed by the set, i.e. there's one map entry for every element e in the set, there's a map entry (key_of(e),e).
What's the idiomatic way (if any) to do this with (modern) C++?
Notes: - The map facade will not be used to insert, delete or change any data. - Answers about ordered map and ordered set are also relevant, although less so. - Performance can be lacking, if I wanted something fast I would just build the map. Simplicity is more important. - The set is constant in the sense that the map facade may assume it never changes. - You may assume there are no redundancies in the set (i.e. no elements with the same key) or suggest a multimap solution.