From ae822a396ce253d563ecbaf4965cc22c6894b764 Mon Sep 17 00:00:00 2001 From: Felipe Magno de Almeida Date: Tue, 20 Dec 2016 15:33:57 -0300 Subject: [PATCH] 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 - void operator()(T&& other) const + void operator()(T&& other) const noexcept { typedef typename std::remove_cv::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>::call(type, static_cast(&buffer), f); } + + template + typename F::result_type visit_unsafe(F f) const + { + return call_visitor<0u, sizeof...(Args), std::tuple>::call(type, static_cast(&buffer), f); + } + + template + typename F::result_type visit_unsafe(F f) + { + return call_visitor<0u, sizeof...(Args), std::tuple>::call(type, static_cast(&buffer), f); + } private: template -- 2.7.4