c++ - Storing pointers to const objects in boost::ptr_unordered_map -
i can't seem make boost::ptr_unordered_map<uint32_t, const foo>
work - underlying implementation looks it's casting things void*
.
do have bite bullet , make methods wrap access const_cast<foo*>
when inserting items, or there i'm missing here? there way store pointers const objects (const foo*
)?
it looks isn't possible.
a workaround wrap access ptr_unordered_map
. insert method should take const auto_ptr , const_cast<foo*>
insert it.
if hand auto_type client code when removing elements, you'll need unpack pointer , transfer const auto_ptr or similar make ownership transfer explicit without leaking non-const references.
this sufficient use case, don't need expose iterator behaviour - it's pure single-element insert/release/look-ups.
Comments
Post a Comment