diff --git a/paddle/pybind/protobuf.cc b/paddle/pybind/protobuf.cc index 7af93cca99a79eec4c4cb29c4117b695a7e3f7ae..673e0ab80b75e7584aa72beeafee32089415655b 100644 --- a/paddle/pybind/protobuf.cc +++ b/paddle/pybind/protobuf.cc @@ -14,8 +14,72 @@ limitations under the License. */ #include "paddle/pybind/protobuf.h" #include +#include #include "paddle/framework/attribute.h" +// Cast boost::variant for PyBind. +// Copy from +// https://github.com/pybind/pybind11/issues/576#issuecomment-269563199 +namespace pybind11 { +namespace detail { + +// Can be replaced by a generic lambda in C++14 +struct variant_caster_visitor : public boost::static_visitor { + return_value_policy policy; + handle parent; + + variant_caster_visitor(return_value_policy policy, handle parent) + : policy(policy), parent(parent) {} + + template + handle operator()(T const &src) const { + return make_caster::cast(src, policy, parent); + } +}; + +template +struct variant_caster; + +template