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:
commit
7d2ead50e5
5 changed files with 254 additions and 173 deletions
|
@ -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(); }
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue