1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-29 06:21:14 +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:
Sergei Zimmerman 2024-11-09 11:58:17 +03:00
parent 492c678162
commit 96eeb6f4ff
8 changed files with 27 additions and 9 deletions

View file

@ -21,7 +21,9 @@ public:
Callback(std::function<void(std::future<T>)> fun) : fun(fun) { }
Callback(Callback && callback) : fun(std::move(callback.fun))
// NOTE: std::function is noexcept move-constructible since C++20.
Callback(Callback && callback) noexcept(std::is_nothrow_move_constructible_v<decltype(fun)>)
: fun(std::move(callback.fun))
{
auto prev = callback.done.test_and_set();
if (prev) done.test_and_set();