I want to store data with both their name and their index. In other words, I want to match the names stringfor the objects, as well as give them an order.
At first I came across a std::vectorkey pair stringand an object. The order was set by the position in the vector.
std::vector<std::pair<std::string, object> >
But this approach seems suboptimal, because it does not automatically verify the uniqueness of names string. In addition, it does not feel like to first group objects in their order, because logically their first-order difference is the name.
I need a data structure that allows access by both name and index.
std::magic<std::string, unsigned int, object> collection;
collection.insert("name", 42, new object());
collection["name"]
collection[42]
? , , , ? , .