From 52df7c35e6fd7094860208c938b503accecf624a Mon Sep 17 00:00:00 2001 From: Treb Connell Date: Fri, 2 Oct 2015 15:10:58 -0700 Subject: [PATCH] Optimize final_act for general case where move is not called --- include/gsl.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/include/gsl.h b/include/gsl.h index dd3d971..0477c02 100644 --- a/include/gsl.h +++ b/include/gsl.h @@ -78,17 +78,18 @@ template 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