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_scope_cat__(name, line) name##line
15#define __xtd_scope_id__(name, line) __xtd_scope_cat__(name, line)
16
17template<class function_t>
18struct __xtd_scope_exit_object__ {
19 __xtd_scope_exit_object__(function_t&& f) : function(std::forward<function_t>(f)) {}
20 ~__xtd_scope_exit_object__() { function(); }
21 function_t function;
22};
23
24template<typename function_t>
25struct __xtd_scope_fail_object__ {
26 __xtd_scope_fail_object__(function_t&& f) : function(std::forward<function_t>(f)) {}
27 ~__xtd_scope_fail_object__() noexcept {if (std::uncaught_exceptions() > exceptions_on_enter) function();}
28 int exceptions_on_enter = std::uncaught_exceptions();
29 function_t function;
30};
31
32template<typename function_t>
33struct __xtd_scope_success_object__ {
34 __xtd_scope_success_object__(function_t&& f) : function(std::forward<function_t>(f)) {}
35 ~__xtd_scope_success_object__() noexcept {if (std::uncaught_exceptions() == exceptions_on_enter) function();}
36 int exceptions_on_enter = std::uncaught_exceptions();
37 function_t function;
38};
@ f
The F key.
Definition console_key.hpp:98
@ function
The FUNCTION modifier key.
Definition keys.hpp:480