finally.hh: delete copy constructor which is a bad idea
Change-Id: I6d0b5736893c44bddc6f5789b452b434f8671b9b
This commit is contained in:
parent
af515baf6e
commit
45f6e3521a
|
@ -9,8 +9,15 @@ class Finally
|
|||
{
|
||||
private:
|
||||
Fn fun;
|
||||
bool movedFrom = false;
|
||||
|
||||
public:
|
||||
Finally(Fn fun) : fun(std::move(fun)) { }
|
||||
~Finally() { fun(); }
|
||||
// Copying Finallys is definitely not a good idea and will cause them to be
|
||||
// called twice.
|
||||
Finally(Finally &other) = delete;
|
||||
Finally(Finally &&other) : fun(std::move(other.fun)) {
|
||||
other.movedFrom = true;
|
||||
}
|
||||
~Finally() { if (!movedFrom) fun(); }
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue