Stripped out final_act into seperate file and renamed it to correspond to the guidelines...

This commit is contained in:
RicoAntonioFelix 2015-09-30 21:22:55 -04:00
parent 398abc8fa6
commit f7a4f895a8

View File

@ -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 <memory>
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 F>
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 <class F>
final_act<F> finally(const F &f) noexcept { return final_act<F>(f); }
template <class 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
template<class T, class U>
T narrow_cast(U u) noexcept { return static_cast<T>(u); }