I would like to have a data structure that stores items of some type ‘Key’ but additionally provides an access to the memory location where it is stored. More specifically, consider the following types:
struct ItemPtr;
struct Item
{
Key key;
ItemPtr* ptr;
};
struct ItemPtr
{
Item* item;
};
Item’s should be stored in something like std::unordered_set; I need to be able to add item, remove item, and find the item by ‘key’. ItemPtr’s will be stored in a separate data structure; I will write my own code that will move ItemPtr’s around. There should be one-to-one correspondence between Item’s and ItemPtr’s (with corresponding pointers pointing to each other). Therefore, whenever std::unordered_set moves Item i to a different location, it should update i->ptr->item accordingly.
Is it possible to achieve this with std, or do I need to reimplement std::unordered_set ?
Thanks in advance for any suggestions!
cppuser is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
3