Quellcode durchsuchen

Templateparameter names adapted from P0052.

main
offa vor 7 Jahren
Ursprung
Commit
82cbd1f5a8
1 geänderte Dateien mit 16 neuen und 16 gelöschten Zeilen
  1. +16
    -16
      include/scope_exit.h

+ 16
- 16
include/scope_exit.h Datei anzeigen

namespace sr namespace sr
{ {


template<class Deleter>
template<class EF>
class scope_exit class scope_exit
{ {
public: 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_exit(D&& deleter) : m_exitFunction(std::move(deleter)),
explicit scope_exit(EFP&& deleter) : m_exitFunction(std::move(deleter)),
m_execute_on_destruction(true) m_execute_on_destruction(true)
{ {
} }


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_exit(D&& deleter) try : m_exitFunction(deleter),
explicit scope_exit(EFP&& deleter) try : m_exitFunction(deleter),
m_execute_on_destruction(true) m_execute_on_destruction(true)
{ {
} }


scope_exit(const scope_exit&) = delete; scope_exit(const scope_exit&) = delete;


template<class T = Deleter,
template<class T = EF,
std::enable_if_t<std::is_nothrow_move_constructible<T>::value, int> = 0 std::enable_if_t<std::is_nothrow_move_constructible<T>::value, int> = 0
> >
scope_exit(scope_exit&& other) : m_exitFunction(std::move(other.m_exitFunction)), scope_exit(scope_exit&& other) : m_exitFunction(std::move(other.m_exitFunction)),
other.release(); other.release();
} }


template<class T = Deleter,
template<class T = EF,
std::enable_if_t<!std::is_nothrow_move_constructible<T>::value, int> = 0 std::enable_if_t<!std::is_nothrow_move_constructible<T>::value, int> = 0
> >
scope_exit(scope_exit&& other) : m_exitFunction(other.m_exitFunction), scope_exit(scope_exit&& other) : m_exitFunction(other.m_exitFunction),


private: private:


Deleter m_exitFunction;
EF m_exitFunction;
bool m_execute_on_destruction; bool m_execute_on_destruction;
}; };




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


} }

Laden…
Abbrechen
Speichern