xtd 1.0.0
Loading...
Searching...
No Matches
scope_fail.hpp
Go to the documentation of this file.
1
4#pragma once
5#include "action_callable.hpp"
6#include "unused.hpp"
7#include <exception>
8#include <utility>
9
11namespace xtd {
65 struct scope_fail {};
66
68 template<typename function_t>
69 requires xtd::action_callable<function_t> && std::is_nothrow_invocable_v<function_t&>
70 struct __xtd_scope_fail_object__ {
71 __xtd_scope_fail_object__(function_t&& f) : function(std::forward<function_t>(f)) {}
72 ~__xtd_scope_fail_object__() noexcept {if (std::uncaught_exceptions() > exceptions_on_enter) function();}
73 int exceptions_on_enter = std::uncaught_exceptions();
74 function_t function;
75 };
76
77 template<typename function_t>
78 requires xtd::action_callable<function_t> && std::is_nothrow_invocable_v<function_t&>
79 auto operator+(scope_fail, function_t&& function) {
80 return __xtd_scope_fail_object__<function_t> {std::forward<function_t>(function)};
81 }
83}
84
138#define scope_fail_ \
139 [[maybe_unused]] auto __ = xtd::scope_fail {} + [&]()
Contains xtd::action_callable concept.
Definition action_callable.hpp:11
constexpr auto operator+(left_t left, right_t right)
Add the specified left and right operands.
Definition add.hpp:100
@ f
The F key.
Definition console_key.hpp:98
@ function
The FUNCTION modifier key.
Definition keys.hpp:480
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
Nowadays, every C++ developer is familiar with the Resource Acquisition Is Initialization (RAII) tech...
Definition scope_fail.hpp:65
Contains __ and unused_ keywords.