Преглед изворни кода

Special handling for exception while move-construction added.

Related to #61: Exceptions are rethrown.
main
offa пре 7 година
родитељ
комит
5067e54b89
1 измењених фајлова са 18 додато и 0 уклоњено
  1. +18
    -0
      include/unique_resource.h

+ 18
- 0
include/unique_resource.h Прегледај датотеку

@@ -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()

Loading…
Откажи
Сачувај