Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
scoped_exit.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <utility>
4
5namespace fc {
6
7 template<typename Callback>
8 class scoped_exit {
9 public:
10 template<typename C>
11 scoped_exit( C&& c ):callback( std::forward<C>(c) ){}
12
14 :callback( std::move( mv.callback ) ),canceled(mv.canceled)
15 {
16 mv.canceled = true;
17 }
18
19 scoped_exit( const scoped_exit& ) = delete;
20 scoped_exit& operator=( const scoped_exit& ) = delete;
21
23 if (!canceled)
24 try { callback(); } catch( ... ) {}
25 }
26
27 void cancel() { canceled = true; }
28
29 private:
30 Callback callback;
31 bool canceled = false;
32 };
33
34 template<typename Callback>
36 return scoped_exit<Callback>( std::forward<Callback>(c) );
37 }
38
39}
scoped_exit & operator=(const scoped_exit &)=delete
scoped_exit(const scoped_exit &)=delete
scoped_exit(scoped_exit &&mv)
namespace sysio::chain
Definition authority.cpp:3
scoped_exit< Callback > make_scoped_exit(Callback &&c)
Definition name.hpp:106