Fixes leaks and adds unique_resource class to make leaking from std::vector<AST::AstNode*> (and similar classes, but this one is used quite often) harder.
The unique_resource works like unique_ptr, but wraps object of any type (not only pointers) and uses provided Deleter functor to delete that resource when needed. Default deleter that deletes all pointers in the range is provided for any range of pointers (i.e. any type T where *std::begin(t) is a pointer when t is an object of that type).
*x (and x->) returns reference to the resource, it doesn't dereference any pointers. Such behavior of this operator is already used in e.g. std::optional.
Fixes leaks and adds
unique_resource
class to make leaking fromstd::vector<AST::AstNode*>
(and similar classes, but this one is used quite often) harder.The
unique_resource
works likeunique_ptr
, but wraps object of any type (not only pointers) and uses provided Deleter functor to delete that resource when needed. Default deleter that deletes all pointers in the range is provided for any range of pointers (i.e. any typeT
where*std::begin(t)
is a pointer whent
is an object of that type).The class is inspired by
std::experimental::unique_resource
, but the API is closed tounique_ptr
. Main differences:release()
returns resource by value*x
(andx->
) returns reference to the resource, it doesn't dereference any pointers. Such behavior of this operator is already used in e.g.std::optional
.