Fix #128 rename final_act to final_action

This commit is contained in:
Treb Connell 2015-10-05 14:52:02 -07:00
parent 3fd9f249da
commit 9d89f1e5ae

View File

@ -73,30 +73,30 @@ using owner = T;
// GSL.util: utilities
//
// final_act allows you to ensure something gets run at the end of a scope
// final_action allows you to ensure something gets run at the end of a scope
template <class F>
class final_act
class final_action
{
public:
explicit final_act(F f) noexcept : f_(std::move(f)), invoke_(true) {}
explicit final_action(F f) noexcept : f_(std::move(f)), invoke_(true) {}
final_act(final_act&& other) noexcept : f_(std::move(other.f_)), invoke_(other.invoke_) { other.invoke_ = false; }
final_act(const final_act&) = delete;
final_act& operator=(const final_act&) = delete;
final_action(final_action&& other) noexcept : f_(std::move(other.f_)), invoke_(other.invoke_) { other.invoke_ = false; }
final_action(const final_action&) = delete;
final_action& operator=(const final_action&) = delete;
~final_act() noexcept { if (invoke_) f_(); }
~final_action() noexcept { if (invoke_) f_(); }
private:
F f_;
bool invoke_;
};
// finally() - convenience function to generate a final_act
// finally() - convenience function to generate a final_action
template <class F>
final_act<F> finally(const F &f) noexcept { return final_act<F>(f); }
final_action<F> finally(const F &f) noexcept { return final_action<F>(f); }
template <class F>
final_act<F> finally(F &&f) noexcept { return final_act<F>(std::forward<F>(f)); }
final_action<F> finally(F &&f) noexcept { return final_action<F>(std::forward<F>(f)); }
// narrow_cast(): a searchable way to do narrowing casts of values
template<class T, class U>