I think this is a standard question but still I'm unable to find a solution or this. I might be missing something very basic.
All I want to do is to access (read only) the data within a std::shared_ptr<std::map<int, int>>
.
The only way I could find is to actually get the object beneath the shared pointer and use it as a normal object:
shared_ptr<map<int, int>> tmap =
make_shared<const map<int,int>>(initializer_list<std::map<int,int>::value_type>{{1, 1}});
auto someMap = *(tmap.get());
cout << someMap[1];
Though this works I would prefer to use it as a shared_ptr if possible.
I was able to find this SO question related to the "[]" operator for shared pointers but again i am not sure on how to use it. For the sake of completeness I would also like to know how to modify this data as well.
TIA
Edit: removed the const from the shared_ptr. Please note that my focus is on accessing the data inside of the shared pointer of a map and not the const part of it.