Optimize final_act for general case where move is not called

This commit is contained in:
Treb Connell 2015-10-02 15:10:58 -07:00
parent df88352c1d
commit 52df7c35e6

View File

@ -78,17 +78,18 @@ template <class F>
class final_act
{
public:
explicit final_act(F f) noexcept : f_(std::move(f)), invoke_(true) {}
explicit final_act(F f) noexcept : f_(std::move(f)) {}
final_act(final_act&& other) noexcept : f_(std::move(other.f_)), invoke_(true) { other.invoke_ = false; }
final_act(final_act&& other) noexcept : f_(std::move(other.f_)) { other.f_ = NoAction; }
final_act(const final_act&) = delete;
final_act& operator=(const final_act&) = delete;
~final_act() noexcept { if (invoke_) f_(); }
~final_act() noexcept { f_(); }
private:
F f_;
bool invoke_;
static void NoAction(){}
};
// finally() - convenience function to generate a final_act