NexusForce 1.0.0
A Modern C++ Library with extended functionality, web components, and utility libraries
载入中...
搜索中...
未找到
scope_exit< Func > 模板类 参考

作用域退出守卫 更多...

#include <scope.hpp>

Public 成员函数

template<typename F, enable_if_t<!is_same_v< remove_cvref_t< F >, scope_exit > &&is_constructible_v< Func, F > &&!is_nothrow_constructible_v< Func, F >, int > = 0>
 scope_exit (F &&func)
 构造函数(异常不安全)
template<typename F, enable_if_t<!is_same_v< remove_cvref_t< F >, scope_exit > &&is_constructible_v< Func, F > &&is_nothrow_constructible_v< Func, F >, int > = 0>
 scope_exit (F &&func) noexcept
 构造函数(异常安全)
 scope_exit (scope_exit &&rhs) noexcept(is_nothrow_move_constructible_v< Func >)
 移动构造函数
 ~scope_exit () noexcept
 析构函数
void release () noexcept
 释放守卫

详细描述

template<typename Func>
class scope_exit< Func >

作用域退出守卫

模板参数
Func可调用对象类型

在作用域退出时无条件执行指定的函数(无论是否发生异常)。

注解
守卫对象的析构函数不应抛出异常。 如果函数可能抛出异常,建议使用scope_fail或scope_success。

在文件 scope.hpp45 行定义.

构造及析构函数说明

◆ scope_exit() [1/3]

template<typename Func>
template<typename F, enable_if_t<!is_same_v< remove_cvref_t< F >, scope_exit > &&is_constructible_v< Func, F > &&!is_nothrow_constructible_v< Func, F >, int > = 0>
scope_exit< Func >::scope_exit ( F && func)
inlineexplicit

构造函数(异常不安全)

模板参数
F函数对象类型
参数
func要执行的函数对象

如果函数对象构造过程中抛出异常,会立即执行func()进行清理。

在文件 scope.hpp60 行定义.

引用了 forward().

被这些函数引用 scope_exit().

◆ scope_exit() [2/3]

template<typename Func>
template<typename F, enable_if_t<!is_same_v< remove_cvref_t< F >, scope_exit > &&is_constructible_v< Func, F > &&is_nothrow_constructible_v< Func, F >, int > = 0>
scope_exit< Func >::scope_exit ( F && func)
inlineexplicitnoexcept

构造函数(异常安全)

模板参数
F函数对象类型
参数
func要执行的函数对象

如果函数对象的构造不抛出异常,使用此版本提高性能。

在文件 scope.hpp76 行定义.

◆ scope_exit() [3/3]

template<typename Func>
scope_exit< Func >::scope_exit ( scope_exit< Func > && rhs)
inlinenoexcept

移动构造函数

参数
rhs要移动的守卫对象

转移所有权,原守卫对象被释放。

在文件 scope.hpp88 行定义.

引用了 is_nothrow_move_constructible_v, move() , 以及 scope_exit().

◆ ~scope_exit()

template<typename Func>
scope_exit< Func >::~scope_exit ( )
inlinenoexcept

析构函数

如果守卫处于激活状态,执行函数对象。 必须保证不抛出异常。

在文件 scope.hpp101 行定义.

成员函数说明

◆ release()

template<typename Func>
void scope_exit< Func >::release ( )
inlinenoexcept

释放守卫

使守卫不再执行清理操作,转移所有权后使用。

在文件 scope.hpp112 行定义.


该类的文档由以下文件生成: