mirror of
https://github.com/microsoft/GSL.git
synced 2024-11-03 17:56:43 -05:00
Stripped out final_act into seperate file and renamed it to correspond to the guidelines...
This commit is contained in:
parent
398abc8fa6
commit
f7a4f895a8
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
#include "array_view.h" // array_view, strided_array_view...
|
#include "array_view.h" // array_view, strided_array_view...
|
||||||
#include "string_view.h" // zstring, string_view, zstring_builder...
|
#include "string_view.h" // zstring, string_view, zstring_builder...
|
||||||
|
#include "final_action.h" // final_action, finally...
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace gsl
|
namespace gsl
|
||||||
@ -45,31 +46,6 @@ using owner = T;
|
|||||||
// GSL.util: utilities
|
// 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
|
// 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) noexcept { return static_cast<T>(u); }
|
T narrow_cast(U u) noexcept { return static_cast<T>(u); }
|
||||||
|
Loading…
Reference in New Issue
Block a user