forked from enlightenment/efl
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:
parent
3704173017
commit
ae822a396c
|
@ -142,7 +142,7 @@ struct destroy_visitor
|
||||||
{
|
{
|
||||||
typedef void result_type;
|
typedef void result_type;
|
||||||
template <typename T>
|
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;
|
typedef typename std::remove_cv<typename std::remove_reference<T>::type>::type type;
|
||||||
other.~type();
|
other.~type();
|
||||||
|
@ -229,13 +229,16 @@ struct variant
|
||||||
|
|
||||||
void destroy()
|
void destroy()
|
||||||
{
|
{
|
||||||
destroy_unsafe();
|
if(type != -1)
|
||||||
type = -1;
|
{
|
||||||
|
destroy_unsafe();
|
||||||
|
type = -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void destroy_unsafe()
|
void destroy_unsafe()
|
||||||
{
|
{
|
||||||
visit(destroy_visitor());
|
visit_unsafe(destroy_visitor());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool empty() const
|
bool empty() const
|
||||||
|
@ -264,6 +267,18 @@ struct variant
|
||||||
else
|
else
|
||||||
return call_visitor<0u, sizeof...(Args), std::tuple<Args...>>::call(type, static_cast<void*>(&buffer), f);
|
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:
|
private:
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
|
Loading…
Reference in New Issue