Pārlūkot izejas kodu

Special handling for exception while move-construction added.

Related to #61: Exceptions are rethrown.
main
offa pirms 7 gadiem
vecāks
revīzija
5067e54b89
1 mainītis faili ar 18 papildinājumiem un 0 dzēšanām
  1. +18
    -0
      include/unique_resource.h

+ 18
- 0
include/unique_resource.h Parādīt failu

@@ -101,6 +101,7 @@ namespace sr
d(r);
}

template<class TR = R, std::enable_if_t<std::is_nothrow_move_constructible<TR>::value, int> = 0>
unique_resource(unique_resource&& other) noexcept(std::is_nothrow_move_constructible<R>::value
&& std::is_nothrow_move_constructible<D>::value)
: m_resource(forward_if_nothrow_move_constructible<R>(std::forward<R>(other.m_resource))),
@@ -109,6 +110,23 @@ namespace sr
{
}

template<class TR = R, std::enable_if_t<!std::is_nothrow_move_constructible<TR>::value, int> = 0>
unique_resource(unique_resource&& other) noexcept(std::is_nothrow_move_constructible<R>::value
&& std::is_nothrow_move_constructible<D>::value)
try : m_resource(forward_if_nothrow_move_constructible<R>(std::forward<R>(other.m_resource))),
m_deleter(forward_if_nothrow_move_constructible<D>(std::forward<D>(other.m_deleter))),
m_execute_on_destruction(std::exchange(other.m_execute_on_destruction, false))
{
}
catch( ... )
{

other.get_deleter()(other.m_resource);
other.release();
throw;
}


unique_resource(const unique_resource&) = delete;

~unique_resource()

Notiek ielāde…
Atcelt
Saglabāt