CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
scope_guard.h
1
3#ifndef _aspose_system_scope_guard_h_
4#define _aspose_system_scope_guard_h_
5
6#include <exception>
7
8namespace System
9{
10
14template <typename F>
16{
19 ScopeGuard(F f) : f(f)
20 {}
21#if defined(_MSC_VER)
22#pragma warning(push)
23// Warning C4722: destructor never returns, potential memory leak.
24#pragma warning(disable : 4722)
25#endif
27 ~ScopeGuard() noexcept(false)
28 {
29#ifdef __cpp_lib_uncaught_exceptions
30 if (std::uncaught_exceptions() > 0)
31#else
32 if (std::uncaught_exception()) // Deprecated since C++ 17
33#endif
34 {
35 // "finally" during exception (unwinding stack)
36 // need prevent double exception and process termination
37 try
38 {
39 f();
40 }
41 catch (...)
42 {
43 }
44 }
45 else
46 {
47 f();
48 }
49 }
50#if defined(_MSC_VER)
51#pragma warning(pop)
52#endif
53private:
55 F f;
56};
57
58// auto guard = MakeScopeGuard([&](){
59// .....
60// });
65template <typename F>
67{
68 return ScopeGuard<F>(f);
69};
70
71} // namespace System
72#endif // _aspose_system_scope_guard_h_
Definition: db_command.h:9
ScopeGuard< F > MakeScopeGuard(F f)
A factory function that creates instances of ScopedGuard class.
Definition: scope_guard.h:66
The service class that provides services for running a particular function object when an instance of...
Definition: scope_guard.h:16
~ScopeGuard() noexcept(false)
Invokes the function object passed to the constructor.
Definition: scope_guard.h:27
ScopeGuard(F f)
Constructs an instance that is set up to invoke the specified function object.
Definition: scope_guard.h:19