diff --git a/include/eigenpy/variant.hpp b/include/eigenpy/variant.hpp index e84a4e95c..56c171e2d 100644 --- a/include/eigenpy/variant.hpp +++ b/include/eigenpy/variant.hpp @@ -10,6 +10,7 @@ #include #include #include +#include #ifdef EIGENPY_WITH_CXX17_SUPPORT #include @@ -23,6 +24,10 @@ namespace details { template struct VariantVisitorType {}; +/// Allow to get all alternatives in a boost::mpl vector +template +struct VariantAlternatives{}; + #ifdef EIGENPY_WITH_CXX17_SUPPORT /// std::variant implementation @@ -31,13 +36,18 @@ struct VariantVisitorType > { typedef std::variant variant_type; typedef ResultType result_type; - template - static result_type visit(Visitor&& visitor, Alternatives&&... alternatives) { + template + static result_type visit(Visitor&& visitor, Visitable&& v) { return std::visit(std::forward(visitor), - std::forward(alternatives)...); + std::forward(v)); } }; +template +struct VariantAlternatives>{ + typedef boost::mpl::vector types; +}; + #endif /// boost::variant implementation @@ -53,6 +63,11 @@ struct VariantVisitorType > } }; +template +struct VariantAlternatives>{ + typedef typename boost::variant::types types; +}; + /// Convert {boost,std}::variant alternative to a Python object. /// This converter copy the alternative. template @@ -61,8 +76,8 @@ struct VariantValueToObject : VariantVisitorType { typedef typename Base::result_type result_type; typedef typename Base::variant_type variant_type; - static result_type convert(const variant_type& gm) { - return Base::visit(VariantValueToObject(), gm); + static result_type convert(const variant_type& v) { + return Base::visit(VariantValueToObject(), v); } template @@ -81,8 +96,8 @@ struct VariantRefToObject : VariantVisitorType { typedef typename Base::result_type result_type; typedef typename Base::variant_type variant_type; - static result_type convert(const variant_type& gm) { - return Base::visit(VariantRefToObject(), gm); + static result_type convert(const variant_type& v) { + return Base::visit(VariantRefToObject(), v); } template @@ -102,8 +117,8 @@ struct VariantConverter { template struct apply { struct type { - PyObject* operator()(const variant_type& gm) const { - return VariantRefToObject::convert(gm); + PyObject* operator()(const variant_type& v) const { + return VariantRefToObject::convert(v); } #ifndef BOOST_PYTHON_NO_PY_SIGNATURES @@ -169,8 +184,9 @@ struct VariantConverter { static void registration() { typedef details::VariantValueToObject variant_to_value; + typedef typename details::VariantAlternatives::types types; boost::python::to_python_converter(); - boost::mpl::for_each( + boost::mpl::for_each( details::VariantImplicitlyConvertible()); } };