You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
any_tidy_ptr<T> is basically unique_ptr<T, std::function<void(T*)>>.
Why?
Sometimes you want to manage some memory and clean it up when you are done, but you don't really care where it came from - that's SEP - Someone Else's Problem.
Motivational example: an Image class that accepts pixels allocated from various sources.
any_tidy_ptr<Foo> p0; // empty
any_tidy_ptr<Foo> p1(new Foo); // just like unique_ptr<Foo>
Foo local;
any_tidy_ptr<Foo> p2(&local, nullptr); // no deleter
any_tidy_ptr<Foo> p3(myFooAlloc(), myFooDelete); // custom deleter
std::shared_ptr<Foo> sp = std::make_shared<Foo>();
any_tidy_ptr<Foo> p4 = sp; // copies sp, deleter will sp.reset()
std::unique_ptr<Foo> up = std::make_unique<Foo>();
any_tidy_ptr<Foo> p5 = std::move(up);