mirror of
https://github.com/NixOS/nix
synced 2025-06-30 19:57:59 +02:00
refactor(treewide): make some move ctors noexcept where appropriate
This is good practice to avoid pessimisations. Left comments for the reasoning why ctors should be noexcept. There are some tricky cases where we intentionally want throwing move ctors/assignments. But those cases should really be reviewed, since some of those can be replaced with more idiomatic copy/move-and-swap.
This commit is contained in:
parent
492c678162
commit
96eeb6f4ff
8 changed files with 27 additions and 9 deletions
|
@ -20,7 +20,11 @@ public:
|
|||
// 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)) {
|
||||
// NOTE: Move constructor can be nothrow if the callable type is itself nothrow
|
||||
// move-constructible.
|
||||
Finally(Finally && other) noexcept(std::is_nothrow_move_constructible_v<Fn>)
|
||||
: fun(std::move(other.fun))
|
||||
{
|
||||
other.movedFrom = true;
|
||||
}
|
||||
~Finally() noexcept(false)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue