I am implementing a type T. Although this is not a requirement, users of this type may benefit from move semantic, that is T(T&&) and T& operator=(T&&).
Since T contains std::function's as member data, I cannot implement move semantic with the noexcept guarantees, which would make T less useful for the user.
Also, for the above reason, my implementation cannot be as simple as: T(&&) noexcept = default and T& operator=(T&&) noexcept = default
The alternative would be to either offer the user the non-noexcept versions: T(&&) = default and T& operator=(T&&) = default; or implement my user defined noexcept move semantic in terms of std::function::swap() (which is guaranteed to be noexcept). In the latter case, I would unfortunately have to take care of all the other member data other than std::function's (ugly!).
So, there are three options:
T(&&) = default and T& operator=(T&&) = default
T(&&) noexcept {/* lot of code */} and T& operator=(T&&) noexcept {/* lot of code */}
I know the question is rather subjective, but What would you opt for?
Assuming you really want the noexcept move, you can reduce the amount of boilerplate for option #3 by either:
std::functions, orfunction in. It just needs to implement the move ctor and assignment operator using swap, and default everything else. OK, you'll also need to either expose the function member or forward the function call operator.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With