eina-cxx: Add visit_unsafe to eina::variant and make ~variant possibly noexcept

visit_unsafe member function visits the variant but assumes the
pre-condition that the variant is not empty. This avoids the
possibility of throwing an exception when the destructors
of the types used in variant are also guaranteed to be
noexcept.

CID 1367508
This commit is contained in:
Felipe Magno de Almeida 2016-12-20 15:33:57 -03:00
parent 3704173017
commit ae822a396c
1 changed files with 19 additions and 4 deletions

View File

@ -142,7 +142,7 @@ struct destroy_visitor
{
typedef void result_type;
template <typename T>
void operator()(T&& other) const
void operator()(T&& other) const noexcept
{
typedef typename std::remove_cv<typename std::remove_reference<T>::type>::type type;
other.~type();
@ -229,13 +229,16 @@ struct variant
void destroy()
{
destroy_unsafe();
type = -1;
if(type != -1)
{
destroy_unsafe();
type = -1;
}
}
void destroy_unsafe()
{
visit(destroy_visitor());
visit_unsafe(destroy_visitor());
}
bool empty() const
@ -264,6 +267,18 @@ struct variant
else
return call_visitor<0u, sizeof...(Args), std::tuple<Args...>>::call(type, static_cast<void*>(&buffer), f);
}
template <typename F>
typename F::result_type visit_unsafe(F f) const
{
return call_visitor<0u, sizeof...(Args), std::tuple<Args...>>::call(type, static_cast<const void*>(&buffer), f);
}
template <typename F>
typename F::result_type visit_unsafe(F f)
{
return call_visitor<0u, sizeof...(Args), std::tuple<Args...>>::call(type, static_cast<void*>(&buffer), f);
}
private:
template <typename T>