I have the 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 didn't really found much information whether it is supported that I specialise default_delete
and whether shared_ptr
also uses default_delete
by default.
It works like intended with Clang 5.0.0.
So, is it supported?
What if the STL implementation has a different internal namespace? It wouldn't find my declaration then? But it should error about the declaration then.
default_delete
is only allowed if it preserves the existing semantics. (Yes, that means it is allowed, but quite pointless)std::unique_ptr
when no deleter is specified. So this is another way of globally overriding the default destruction policy for some specific type used bystd::unique_ptr
. And I thought that the same applies butshared_ptr
, and it does also in Clangs STL implementation, but it seems not according to the C++ standard.std::default_delete
is (only) forstd::unique_ptr
, not forstd::shared_ptr
...std::shared_ptr
, but useful forstd::unique_ptr
.