felipealmeida pushed a commit to branch master. http://git.enlightenment.org/core/efl.git/commit/?id=ae822a396ce253d563ecbaf4965cc22c6894b764
commit ae822a396ce253d563ecbaf4965cc22c6894b764 Author: Felipe Magno de Almeida <fel...@expertisesolutions.com.br> Date: Tue Dec 20 15:33:57 2016 -0300 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 --- src/bindings/cxx/eina_cxx/eina_variant.hh | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/bindings/cxx/eina_cxx/eina_variant.hh b/src/bindings/cxx/eina_cxx/eina_variant.hh index df24aea..358688a 100644 --- a/src/bindings/cxx/eina_cxx/eina_variant.hh +++ b/src/bindings/cxx/eina_cxx/eina_variant.hh @@ -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> --