mirror of
https://github.com/microsoft/GSL.git
synced 2024-11-03 17:56:43 -05:00
Adding noexcept to finally, final_act, narrow_cast. Fixes #92.
This commit is contained in:
parent
c5c8a25f34
commit
831c6926df
@ -50,13 +50,13 @@ template <class F>
|
|||||||
class final_act
|
class final_act
|
||||||
{
|
{
|
||||||
public:
|
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(const final_act&) = delete;
|
||||||
final_act& operator=(const final_act&) = delete;
|
final_act& operator=(const final_act&) = delete;
|
||||||
|
|
||||||
~final_act() { if (invoke_) f_(); }
|
~final_act() noexcept { if (invoke_) f_(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
F f_;
|
F f_;
|
||||||
@ -65,14 +65,14 @@ private:
|
|||||||
|
|
||||||
// finally() - convenience function to generate a final_act
|
// finally() - convenience function to generate a final_act
|
||||||
template <class F>
|
template <class F>
|
||||||
final_act<F> finally(const F &f) { return final_act<F>(f); }
|
final_act<F> finally(const F &f) noexcept { return final_act<F>(f); }
|
||||||
|
|
||||||
template <class F>
|
template <class F>
|
||||||
final_act<F> finally(F &&f) { return final_act<F>(std::forward<F>(f)); }
|
final_act<F> finally(F &&f) noexcept { return final_act<F>(std::forward<F>(f)); }
|
||||||
|
|
||||||
// narrow_cast(): a searchable way to do narrowing casts of values
|
// narrow_cast(): a searchable way to do narrowing casts of values
|
||||||
template<class T, class U>
|
template<class T, class U>
|
||||||
T narrow_cast(U u) { return static_cast<T>(u); }
|
T narrow_cast(U u) noexcept { return static_cast<T>(u); }
|
||||||
|
|
||||||
struct narrowing_error : public std::exception {};
|
struct narrowing_error : public std::exception {};
|
||||||
// narrow() : a checked version of narrow_cast() that throws if the cast changed the value
|
// narrow() : a checked version of narrow_cast() that throws if the cast changed the value
|
||||||
|
Loading…
Reference in New Issue
Block a user