From 831c6926df2dd17a691abf7d84137435ff172025 Mon Sep 17 00:00:00 2001 From: Neil MacIntosh Date: Wed, 30 Sep 2015 15:10:24 -0700 Subject: [PATCH] Adding noexcept to finally, final_act, narrow_cast. Fixes #92. --- include/gsl.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/include/gsl.h b/include/gsl.h index 5d4c840..e15ca5c 100644 --- a/include/gsl.h +++ b/include/gsl.h @@ -50,13 +50,13 @@ template class final_act { public: - explicit final_act(F f) : f_(std::move(f)), invoke_(true) {} + explicit final_act(F f) noexcept : f_(std::move(f)), invoke_(true) {} - final_act(final_act&& other) : f_(std::move(other.f_)), invoke_(true) { other.invoke_ = false; } + 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() { if (invoke_) f_(); } + ~final_act() noexcept { if (invoke_) f_(); } private: F f_; @@ -65,14 +65,14 @@ private: // finally() - convenience function to generate a final_act template -final_act finally(const F &f) { return final_act(f); } +final_act finally(const F &f) noexcept { return final_act(f); } template -final_act finally(F &&f) { return final_act(std::forward(f)); } +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) { return static_cast(u); } +T narrow_cast(U u) noexcept { return static_cast(u); } struct narrowing_error : public std::exception {}; // narrow() : a checked version of narrow_cast() that throws if the cast changed the value