drop-in replacement class for a raw ptr #barebones

(see also my little post on auto_ptr implementation, and http://www.revergestudios.com/reblog/index.php?n=ReCode.SharedPtr) Any Smart pointer must be a drop-in replacement for a raw ptr. At the minimum this requires

– overload deref operator
– overload arrow operator
– when an existing func requires a raw ptr argument, you can pass in smart ptr — Implicit conversion by …. [1]
– when an existing func returns raw ptr, but you receive it in a smart ptr — Implicit conversion by …… [2]

Above the minimum, it needs
+ [optional] overload increment/decrement? This is indeed part of the drop-in deal. Not easy. Not widely implemented.
+ ctor, dtor, copier, op=
+ how about explicit cast between smart ptr and the corresponding [3] raw ptr? Not part of drop-in replacement.
+ overload address-of operator? I feel no need
+ overload reference to the smart ptr? I feel no need

However, there’s a more stringent requirement that shared_ptr, auto_ptr don’t meet … same size as a raw ptr. Which smart ptr can achieve this? [5]

How about const_cast, dynamic_cast and upcast on raw pointer??

[3] smart ptr is parametrized so each concrete smart ptr type covers one type of raw ptr
[2] conversion ctor??
[1] operator-overload conversion method
[5] intrusive_ptr

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s