Advertisement Jump to content
Sign in to follow this  

Concerning std::auto_ptr

This topic is 2243 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I find myself creating RAII templates for COM and for IrrKlang objects that behave in a very similar fashion to std::auto_ptr (because I intentionally model them after that behavior). The reason for this is that in both cases the objects manage lifetime using internal reference counting that triggers deconstruction by calls to a member function: comObj->Release() and irkObj->drop(), so std::auto_ptr's simple 'delete' won't cut it here.

The documentation I have says that std::auto_ptr is deprecated, so I'm guessing that we're supposed to use shared_ptr now, even for unshared pointers. I see that shared_ptr supports custom deletion with functors, but the syntax of it makes it sort of difficult to 'shoehorn' that into a new type. In other words, does anyone know of a way to make a derived type from shared_ptr that uses a custom deleter of a set type? So I could say something like:

[source lang="cpp"]//This does not work because template syntax is stupid:
template<class T> class Releaser {
void operator()(T* p) {

template<class T> class Releasable : public shared_ptr<T, Releaser>;

Releasable<foo> bar(fooPtr); //will call fooPtr->Release(); on dtor[/source] Edited by Khatharr

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!