1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-06 05:01:48 +02:00

Merge pull request #10083 from lf-/jade/refactor-repl-input

refactor: move the repl input code to its own file
This commit is contained in:
Robert Hensing 2024-03-20 22:37:40 +01:00 committed by GitHub
commit 7d2ead50e5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 254 additions and 173 deletions

View file

@ -1,16 +1,25 @@
#pragma once
///@file
#include <utility>
/**
* A trivial class to run a function at the end of a scope.
*/
template<typename Fn>
class Finally
class [[nodiscard("Finally values must be used")]] 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(); }
};