1#ifndef NEFORCE_CORE_UTILITY_SCOPE_HPP__
2#define NEFORCE_CORE_UTILITY_SCOPE_HPP__
27NEFORCE_BEGIN_NAMESPACE__
45template <
typename Func>
58 template <
typename F, enable_if_t<!is_same_v<remove_cvref_t<F>, scope_exit> && is_constructible_v<Func, F> &&
59 !is_nothrow_constructible_v<Func, F>,
74 template <
typename F, enable_if_t<!is_same_v<remove_cvref_t<F>, scope_exit> && is_constructible_v<Func, F> &&
75 is_nothrow_constructible_v<Func, F>,
80 scope_exit(
const scope_exit&) =
delete;
81 scope_exit& operator=(
const scope_exit&) =
delete;
90 func_pair_(_NEFORCE
move(rhs.func_pair_)) {
104 if (func_pair_.value) {
105 func_pair_.get_base()();
118 void release() noexcept { func_pair_.value =
false; }
121#ifdef NEFORCE_STANDARD_17
122template <
typename Func>
123scope_exit(Func) -> scope_exit<Func>;
135template <
typename Func>
148 template <
typename F, enable_if_t<!is_same_v<remove_cvref_t<F>, scope_fail> && is_constructible_v<Func, F> &&
149 !is_nothrow_constructible_v<Func, F>,
162 template <
typename F, enable_if_t<!is_same_v<remove_cvref_t<F>, scope_fail> && is_constructible_v<Func, F> &&
163 is_nothrow_constructible_v<Func, F>,
168 scope_fail(
const scope_fail&) =
delete;
169 scope_fail& operator=(
const scope_fail&) =
delete;
176 func_pair_(_NEFORCE
move(rhs.func_pair_)) {
191 func_pair_.get_base()();
207#ifdef NEFORCE_STANDARD_17
208template <
typename Func>
209scope_fail(Func) -> scope_fail<Func>;
223template <
typename Func>
234 template <
typename F, enable_if_t<!is_same_v<remove_cvref_t<F>, scope_success> && is_constructible_v<Func, F> &&
235 !is_nothrow_constructible_v<Func, F>,
248 template <
typename F, enable_if_t<!is_same_v<remove_cvref_t<F>, scope_success> && is_constructible_v<Func, F> &&
249 is_nothrow_constructible_v<Func, F>,
254 scope_success(
const scope_success&) =
delete;
255 scope_success& operator=(
const scope_success&) =
delete;
262 func_pair_(_NEFORCE
move(rhs.func_pair_)) {
277 func_pair_.get_base()();
293#ifdef NEFORCE_STANDARD_17
294template <
typename Func>
295scope_success(Func) -> scope_success<Func>;
300NEFORCE_END_NAMESPACE__
static constexpr T max() noexcept
获取类型的最大值
~scope_exit() noexcept
析构函数
scope_exit(F &&func)
构造函数(异常不安全)
scope_exit(scope_exit &&rhs) noexcept(is_nothrow_move_constructible_v< Func >)
移动构造函数
scope_exit(F &&func) noexcept
构造函数(异常安全)
void release() noexcept
释放守卫
scope_fail(F &&func) noexcept
构造函数(异常安全)
~scope_fail() noexcept
析构函数
scope_fail(F &&func)
构造函数(异常不安全)
void release() noexcept
释放守卫
scope_fail(scope_fail &&rhs) noexcept
移动构造函数
scope_success(F &&func) noexcept
构造函数(异常安全)
~scope_success() noexcept
析构函数
void release() noexcept
释放守卫
scope_success(scope_success &&rhs) noexcept(is_nothrow_move_assignable_v< Func >)
移动构造函数
scope_success(F &&func)
构造函数(异常不安全)
constexpr T && forward(remove_reference_t< T > &x) noexcept
完美转发左值
int uncaught_exceptions() noexcept
未捕获的异常数量
constexpr Iterator2 move(Iterator1 first, Iterator1 last, Iterator2 result) noexcept(noexcept(inner::__move_aux(first, last, result)))
移动范围元素
constexpr bool is_nothrow_move_assignable_v
is_nothrow_move_assignable的便捷变量模板
constexpr bool is_nothrow_move_constructible_v
is_nothrow_move_constructible的便捷变量模板