K
K. Frank
Hello Group!
I have a collection.
(It happens to be an unordered_map, hence my earlier question
about possible pointer invalidation, but for the purposes of
this question it could be a map or set, etc.)
In addition to element access through the built-in features
of the collection class, I also want quick access to the first
few elements according to some independent sorting criterion.
Therefore my wrapper class contains not only the underlying
collection, but a helper index that is a (sorted) set of
pointers to values in the collection. I am using raw pointers
for this, basically because I don't see any need to use some
sort of smart pointer.
I do know the various smart pointers have been getting better
designed over the years and are now part of the standard.
Is there a good reason I should be using some sort of smart
pointer? Is there a compelling reason?
Some details: In my particular use case, items are never
removed form the main collection. If they were, of course,
my wrapper class would need to keep the helper index in
sync by also removing the corresponding index -- just as
it keeps the helper index in sync when items are added.
Also, the helper index is used only to access the items,
not to modify or remove them.
Thanks for an smart-pointer wisdom.
K. Frank
I have a collection.
(It happens to be an unordered_map, hence my earlier question
about possible pointer invalidation, but for the purposes of
this question it could be a map or set, etc.)
In addition to element access through the built-in features
of the collection class, I also want quick access to the first
few elements according to some independent sorting criterion.
Therefore my wrapper class contains not only the underlying
collection, but a helper index that is a (sorted) set of
pointers to values in the collection. I am using raw pointers
for this, basically because I don't see any need to use some
sort of smart pointer.
I do know the various smart pointers have been getting better
designed over the years and are now part of the standard.
Is there a good reason I should be using some sort of smart
pointer? Is there a compelling reason?
Some details: In my particular use case, items are never
removed form the main collection. If they were, of course,
my wrapper class would need to keep the helper index in
sync by also removing the corresponding index -- just as
it keeps the helper index in sync when items are added.
Also, the helper index is used only to access the items,
not to modify or remove them.
Thanks for an smart-pointer wisdom.
K. Frank