implicitly_convertible or order of init's problem
Hi. I found some very very strange behaviour. Please, consider next code: struct vector{ vector(){} vector( double ){} vector( const vector& ){} }; struct float_vector{ float_vector(){} float_vector( const float_vector& ){} float_vector( const vector& ){} float_vector( float ){} }; namespace bp = boost::python; BOOST_PYTHON_MODULE( ic_ext ){ bp::class_< float_vector >( "float_vector" ) .def( bp::init< >() ) .def( bp::init< vector const & >() ) .def( bp::init< float >() ) .def( bp::init< const float_vector& >() ); bp::implicitly_convertible< vector const &, float_vector >(); bp::implicitly_convertible< float, float_vector >(); bp::class_< vector >( "vector" ) .def( bp::init< >() ) .def( bp::init< double >() ); bp::implicitly_convertible< double, vector >(); } import ic_ext ic_ext.float_vector( 5.0 ) The last line fails with the error: TypeError: No registered converter was able to extract a C++ reference to type vector from this Python object of type float Question: Why Boost.Python does not use float_vector( float ) constructor? If I reorder the init methods "ic_ext.float_vector( 5.0 )" expression pass: bp::class_< float_vector >( "float_vector" ) .def( bp::init< >() ) .def( bp::init< vector const & >() ) .def( bp::init< const float_vector& >() ) .def( bp::init< float >() ); If I comment out "bp::implicitly_convertible< vector const &, float_vector >();" than "ic_ext.float_vector( 5.0 )" expression pass. It could be nice to understand why this happens. I attached small example that reproduce the problem.( I hope this time I did it right :-) ) Thanks. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/
"Roman Yakovenko" <roman.yakovenko@gmail.com> writes:
If I comment out "bp::implicitly_convertible< vector const &, float_vector >();" than "ic_ext.float_vector( 5.0 )" expression pass.
It could be nice to understand why this happens. I attached small example that reproduce the problem.( I hope this time I did it right :-) )
Please try the following patch to boost/python/converter/implicit.hpp. -- Dave Abrahams Boost Consulting www.boost-consulting.com
On 9/19/06, David Abrahams <dave@boost-consulting.com> wrote:
"Roman Yakovenko" <roman.yakovenko@gmail.com> writes:
If I comment out "bp::implicitly_convertible< vector const &, float_vector >();" than "ic_ext.float_vector( 5.0 )" expression pass.
It could be nice to understand why this happens. I attached small example that reproduce the problem.( I hope this time I did it right :-) )
Please try the following patch to boost/python/converter/implicit.hpp.
The patch corrects the problem. Thank you. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/
participants (2)
-
David Abrahams -
Roman Yakovenko