::value
&& std::is_nothrow_move_constructible::value), int> = 0
>
unique_resource(unique_resource&& other) : m_resource(std::forward(other.m_resource)),
m_deleter(std::forward(other.m_deleter)),
m_execute_on_destruction(std::exchange(other.m_execute_on_destruction, false))
{
}
template::value
|| !std::is_nothrow_move_constructible::value), int> = 0
>
unique_resource(unique_resource&& other) : m_resource(other.m_resource),
m_deleter(other.m_deleter),
m_execute_on_destruction(std::exchange(other.m_execute_on_destruction, false))
{
}
unique_resource(const unique_resource&) = delete;
~unique_resource()
{
if( m_execute_on_destruction == true )
{
m_deleter(m_resource);
}
}
void reset()
{
if( m_execute_on_destruction == true )
{
m_execute_on_destruction = false;
m_deleter(m_resource);
}
}
void release()
{
m_execute_on_destruction = false;
}
const R& get() const noexcept
{
return m_resource;
}
unique_resource& operator=(unique_resource&& other);
unique_resource& operator=(const unique_resource&) = delete;
private:
R m_resource;
D m_deleter;
bool m_execute_on_destruction;
};
template
unique_resource, std::decay_t> make_unique_resource(Resource&& r, Deleter&& d)
{
return unique_resource, std::decay_t>{std::forward(r), std::forward(d)};
}
}
| |