tgockel / zookeeper-cpp

A ZooKeeper client for C++.
http://tgockel.github.io/zookeeper-cpp/
Apache License 2.0
148 stars 40 forks source link

Make result types no-throw move assignable and constructible #123

Closed GuillaumeDua closed 3 years ago

GuillaumeDua commented 3 years ago

Please consider the strong exception guarantee, e.g non-throwing move-assignement/move-assignement.

Current code :

class watch_result final
{
    watch_result(watch_result&&) = default;
    watch_result& operator=(watch_result&&) = default;
}

So

static_assert(std::is_move_assignable_v<watch_result>); // ok
static_assert(std::is_nothrow_move_assignable_v<watch_result>); // KO

Please consider using noexcept for strong exception garantee :

watch_result& operator=(watch_result&&) noexcept = default;
tgockel commented 3 years ago

The types already have a strong exception guarantee. However, making a no-throw guarantee seems ideal here. Simply marking watch_result's move-assignment operator as noexcept would result in a compilation error, as get_result is not no-throw move-assignable. The fix here is to rule-of-6 all the types.