Interesting perspective on shared_ptr

In a discussion with Peter Dimov, following thoughts triggered by the recent posts arguing that after a move, shared_ptr should clear px, it occured to me that perhaps shared_ptr<T> could have T px member instead of T * px. Peter correctly pointed out that in that case, the class template would be called "shared", not "shared_ptr". Note that I would still be able to say shared<foo *> to get (almost) the same thing as shared_ptr<foo>. There are a few things that need clarification, but overall I don't see drawbacks of shared<foo *> compared to shared_ptr<foo>. Peter came up with other potential uses, such as shared<int> which would be implicitly convertible to shared<double>. You can add things like shared<pthread_t>, or shared<HWND>. Speaking of HWND, I already wrote my own win_handle<T>, with partial specialization win_handle<T *> which has a shared_ptr<T> member. All that so I can write win_handle<HWND>, and it only works because HWND happens to be a pointer. Just a wacky idea. :) Emil Dotchevski

Emil Dotchevski wrote:
In a discussion with Peter Dimov, following thoughts triggered by the recent posts arguing that after a move, shared_ptr should clear px, it occured to me that perhaps shared_ptr<T> could have T px member instead of T * px. Peter correctly pointed out that in that case, the class template would be called "shared", not "shared_ptr".
Note that I would still be able to say shared<foo *> to get (almost) the same thing as shared_ptr<foo>. There are a few things that need clarification, but overall I don't see drawbacks of shared<foo *> compared to shared_ptr<foo>.
Peter came up with other potential uses, such as shared<int> which would be implicitly convertible to shared<double>. You can add things like shared<pthread_t>, or shared<HWND>. Speaking of HWND, I already wrote my own win_handle<T>, with partial specialization win_handle<T *> which has a shared_ptr<T> member. All that so I can write win_handle<HWND>, and it only works because HWND happens to be a pointer.
Maybe could add a new shared<T>, but still keep shared_ptr, as a typedef: typedef shared<T*> shared_ptr;
participants (2)
-
Emil Dotchevski
-
gchen