Specialize `std :: default_delete` for` std :: shared_ptr`

I have an idea to do this:

namespace std {
    template<>
    class default_delete<IplImage> {
    public:
        void operator()(IplImage *ptr) const {
            cvReleaseImage(&ptr);
        }
    };
};

typedef std::shared_ptr<IplImage> IplImageObj;

I really did not find much information about whether this is supported by a specialist default_deleteand whether it is used shared_ptrby default default_delete.

It works as with Clang 5.0.0.

So is this supported?

What if the STL implementation has a different internal namespace? Then it would not find my declaration? But in this case there should be an error in the ad.

+4
source share
1 answer

default_delete must be defined in the std namespace, and it should specialize in objects from the std namespace.

namespace std {
template<class T> struct default_delete;
template<class T> struct default_delete<T[]>;

, std::default_delete UB. ( . ).

, shared_ptr default_delete.

  ~ Shared_ptr();

:

- * shared_ptr (use_count() > 1), .

- , * p d, d (p) .

- * p, p.

+2

All Articles