From f7a4f895a8ac958def27b15ce0cc0e7a90b814fd Mon Sep 17 00:00:00 2001 From: RicoAntonioFelix Date: Wed, 30 Sep 2015 21:22:55 -0400 Subject: [PATCH] Stripped out final_act into seperate file and renamed it to correspond to the guidelines... --- include/gsl.h | 26 +------------------------- 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/include/gsl.h b/include/gsl.h index e15ca5c..5a31975 100644 --- a/include/gsl.h +++ b/include/gsl.h @@ -21,6 +21,7 @@ #include "array_view.h" // array_view, strided_array_view... #include "string_view.h" // zstring, string_view, zstring_builder... +#include "final_action.h" // final_action, finally... #include namespace gsl @@ -45,31 +46,6 @@ using owner = T; // GSL.util: utilities // -// final_act allows you to ensure something gets run at the end of a scope -template -class final_act -{ -public: - explicit final_act(F f) noexcept : f_(std::move(f)), invoke_(true) {} - - final_act(final_act&& other) noexcept : f_(std::move(other.f_)), invoke_(true) { other.invoke_ = false; } - final_act(const final_act&) = delete; - final_act& operator=(const final_act&) = delete; - - ~final_act() noexcept { if (invoke_) f_(); } - -private: - F f_; - bool invoke_; -}; - -// finally() - convenience function to generate a final_act -template -final_act finally(const F &f) noexcept { return final_act(f); } - -template -final_act finally(F &&f) noexcept { return final_act(std::forward(f)); } - // narrow_cast(): a searchable way to do narrowing casts of values template T narrow_cast(U u) noexcept { return static_cast(u); }