Sfoglia il codice sorgente

Usage of deprecated factory functions replaced (#88).

main
offa 7 anni fa
parent
commit
2cdfb325b6
1 ha cambiato i file con 7 aggiunte e 7 eliminazioni
  1. +7
    -7
      include/unique_resource.h

+ 7
- 7
include/unique_resource.h Vedi File

> >
explicit unique_resource(RR&& r, DD&& d) noexcept(std::is_nothrow_constructible_v<R, RR> explicit unique_resource(RR&& r, DD&& d) noexcept(std::is_nothrow_constructible_v<R, RR>
&& std::is_nothrow_constructible_v<D, DD>) && std::is_nothrow_constructible_v<D, DD>)
: m_resource(std::forward<RR>(r), make_scope_exit([&r, &d] { d(r); })),
m_deleter(std::forward<DD>(d), make_scope_exit([this, &d] { d(get()); })),
: m_resource(std::forward<RR>(r), scope_exit{[&r, &d] { d(r); }}),
m_deleter(std::forward<DD>(d), scope_exit{[this, &d] { d(get()); }}),
m_execute_on_destruction(true) m_execute_on_destruction(true)
{ {
} }


unique_resource(unique_resource&& other) noexcept(std::is_nothrow_move_constructible_v<R> unique_resource(unique_resource&& other) noexcept(std::is_nothrow_move_constructible_v<R>
&& std::is_nothrow_move_constructible_v<D>) && std::is_nothrow_move_constructible_v<D>)
: m_resource(detail::forward_if_nothrow_move_constructible(other.m_resource.get()), make_scope_exit([] { })),
: m_resource(detail::forward_if_nothrow_move_constructible(other.m_resource.get()), scope_exit{[] { }}),
m_deleter(detail::forward_if_nothrow_move_constructible(other.m_deleter.get()), m_deleter(detail::forward_if_nothrow_move_constructible(other.m_deleter.get()),
make_scope_exit([&other] {
scope_exit{[&other] {
other.get_deleter()(other.m_resource.get()); other.get_deleter()(other.m_resource.get());
other.release(); })),
other.release(); }}),
m_execute_on_destruction(std::exchange(other.m_execute_on_destruction, false)) m_execute_on_destruction(std::exchange(other.m_execute_on_destruction, false))
{ {
} }
template<class RR> template<class RR>
void reset(RR&& r) void reset(RR&& r)
{ {
auto se = make_scope_exit([this, &r] { get_deleter()(r); });
auto se = scope_exit{[this, &r] { get_deleter()(r); }};
reset(); reset();
m_resource.reset(std::forward<RR>(r)); m_resource.reset(std::forward<RR>(r));
m_execute_on_destruction = true; m_execute_on_destruction = true;
&& std::is_nothrow_constructible_v<std::decay_t<D>, D>) && std::is_nothrow_constructible_v<std::decay_t<D>, D>)
{ {
const bool must_release{r == invalid}; const bool must_release{r == invalid};
auto ur = make_unique_resource(r, d);
auto ur = unique_resource{r, d};


if( must_release == true ) if( must_release == true )
{ {

Loading…
Annulla
Salva