浏览代码

Templateparameter names adapted from P0052.

main
offa 7 年前
父节点
当前提交
3fc95d8061
共有 1 个文件被更改,包括 17 次插入17 次删除
  1. +17
    -17
      include/scope_success.h

+ 17
- 17
include/scope_success.h 查看文件

@@ -27,27 +27,27 @@
namespace sr
{

template<class Deleter>
template<class EF>
class scope_success
{
public:

template<class D,
std::enable_if_t<std::is_constructible<Deleter, D>::value, int> = 0,
std::enable_if_t<(!std::is_lvalue_reference<D>::value)
&& std::is_nothrow_constructible<Deleter, D>::value, int> = 0
template<class EFP,
std::enable_if_t<std::is_constructible<EF, EFP>::value, int> = 0,
std::enable_if_t<(!std::is_lvalue_reference<EFP>::value)
&& std::is_nothrow_constructible<EF, EFP>::value, int> = 0
>
explicit scope_success(D&& deleter) : m_deleter(std::move(deleter)),
explicit scope_success(EFP&& deleter) : m_deleter(std::move(deleter)),
m_execute_on_destruction(true),
m_uncaught_on_creation(uncaught_exceptions())
{
}

template<class D,
std::enable_if_t<std::is_constructible<Deleter, D>::value, int> = 0,
std::enable_if_t<std::is_lvalue_reference<D>::value, int> = 0
template<class EFP,
std::enable_if_t<std::is_constructible<EF, EFP>::value, int> = 0,
std::enable_if_t<std::is_lvalue_reference<EFP>::value, int> = 0
>
explicit scope_success(D&& deleter) try : m_deleter(deleter),
explicit scope_success(EFP&& deleter) try : m_deleter(deleter),
m_execute_on_destruction(true),
m_uncaught_on_creation(uncaught_exceptions())
{
@@ -59,7 +59,7 @@ namespace sr

scope_success(const scope_success&) = delete;

template<class T = Deleter,
template<class T = EF,
std::enable_if_t<std::is_nothrow_move_constructible<T>::value, int> = 0
>
scope_success(scope_success&& other) : m_deleter(std::move(other.m_deleter)),
@@ -69,7 +69,7 @@ namespace sr
other.release();
}

template<class T = Deleter,
template<class T = EF,
std::enable_if_t<!std::is_nothrow_move_constructible<T>::value, int> = 0
>
scope_success(scope_success&& other) : m_deleter(other.m_deleter),
@@ -79,7 +79,7 @@ namespace sr
other.release();
}

~scope_success() noexcept(noexcept(std::declval<Deleter>()))
~scope_success() noexcept(noexcept(std::declval<EF>()))
{
if( (m_execute_on_destruction == true) && ( uncaught_exceptions() <= m_uncaught_on_creation ) )
{
@@ -105,16 +105,16 @@ namespace sr
return ( std::uncaught_exception() == true ? 1 : 0 );
}

Deleter m_deleter;
EF m_deleter;
bool m_execute_on_destruction;
int m_uncaught_on_creation;
};


template<class Deleter>
scope_success<std::decay_t<Deleter>> make_scope_success(Deleter&& deleter)
template<class EF>
scope_success<std::decay_t<EF>> make_scope_success(EF&& deleter)
{
return scope_success<std::decay_t<Deleter>>{std::forward<Deleter>(deleter)};
return scope_success<std::decay_t<EF>>{std::forward<EF>(deleter)};
}

}

正在加载...
取消
保存