diff --git a/include/gsl/util b/include/gsl/util index 5e9256f..757be6a 100644 --- a/include/gsl/util +++ b/include/gsl/util @@ -52,7 +52,9 @@ template class final_action { public: - explicit final_action(F f_) : f(std::move(f_)) { } + template + explicit final_action(FF&& ff) : f{std::forward(ff)} { } + ~final_action() { if (invoke) f(); } final_action(final_action&& other) @@ -60,8 +62,8 @@ public: { } final_action(const final_action& rhs) = delete; - final_action& operator=(const final_action&) = delete; - final_action& operator=(final_action&& other) = delete; + void operator=(const final_action&) = delete; + void operator=(final_action&& other) = delete; private: F f; @@ -70,9 +72,9 @@ private: // finally() - convenience function to generate a final_action template -auto finally(F f) noexcept +[[nodiscard]] auto finally(F&& f) noexcept { - return final_action{f}; + return final_action{std::forward(f)}; } // narrow_cast(): a searchable way to do narrowing casts of values