xtd 0.2.0
Loading...
Searching...
No Matches
__xtd_scope.hpp
Go to the documentation of this file.
1
4#pragma once
6#if !defined(__XTD_CORE_INTERNAL__)
7#error "Do not include this file: Internal use only"
8#endif
10
11#include <exception>
12
14#define __xtd_finally_cat__(name, line) name##line
15#define __xtd_finally_id__(name, line) __xtd_finally_cat__(name, line)
16
17#define __xtd_scope_cat__(name, line) name##line
18#define __xtd_scope_id__(name, line) __xtd_scope_cat__(name, line)
19
20template<typename function_t>
21struct __xtd_finally_object__ {
22 __xtd_finally_object__(function_t&& f) : function(std::forward<function_t>(f)) {}
23 ~__xtd_finally_object__() { function(); }
24 function_t function;
25};
26
27template<typename function_t>
28struct __xtd_scope_exit_object__ {
29 __xtd_scope_exit_object__(function_t&& f) : function(std::forward<function_t>(f)) {}
30 ~__xtd_scope_exit_object__() { function(); }
31 function_t function;
32};
33
34template<typename function_t>
35struct __xtd_scope_fail_object__ {
36 __xtd_scope_fail_object__(function_t&& f) : function(std::forward<function_t>(f)) {}
37 ~__xtd_scope_fail_object__() noexcept {if (std::uncaught_exceptions() > exceptions_on_enter) function();}
38 int exceptions_on_enter = std::uncaught_exceptions();
39 function_t function;
40};
41
42template<typename function_t>
43struct __xtd_scope_success_object__ {
44 __xtd_scope_success_object__(function_t&& f) : function(std::forward<function_t>(f)) {}
45 ~__xtd_scope_success_object__() noexcept {if (std::uncaught_exceptions() == exceptions_on_enter) function();}
46 int exceptions_on_enter = std::uncaught_exceptions();
47 function_t function;
48};
@ f
The F key.
Definition console_key.hpp:98
@ function
The FUNCTION modifier key.
Definition keys.hpp:480