[C++-sig] Little problem in Boost.Python implicit.hpp

Ger van Diepen diepen at astron.nl
Tue May 27 09:47:53 CEST 2008


During my work to handle numpy array scalars correctly, I stumbled on a little problem in implicit.hpp making it impossible to use the implicitly_convertible class.

I have a class ValueHolder which is a kind of any class. It can hold values of the basic types and is convertible to types like double and DComplex (a typedef for std::complex<double>).
Now I wanted to use
    boost::python::implicitly_convertible<ValueHolder,int>();
but the compiler gave errors like:

/Users/diepen/conrad/svnConrad/3rdparty/boost/tags/boost-1.34.1/include/boost/python/converter/implicit.hpp: In static member function 'static void boost::python::converter::implicit<Source, Target>::construct(PyObject*, boost::python::converter::rvalue_from_python_stage1_data*) [with Source = casa::ValueHolder, Target = casa::DComplex]':
/Users/diepen/conrad/svnConrad/3rdparty/boost/tags/boost-1.34.1/include/boost/python/implicit.hpp:21:   instantiated from 'void boost::python::implicitly_convertible(boost::type<Target>*, boost::type<Target>*) [with Source = casa::ValueHolder, Target = casa::DComplex]'
pyrap/Converters/PycArrayNP.cc:168:   instantiated from here
/Users/diepen/conrad/svnConrad/3rdparty/boost/tags/boost-1.34.1/include/boost/python/converter/implicit.hpp:37: error: call of overloaded 'complex(casa::ValueHolder&)' is ambiguous
/usr/include/c++/4.0.0/complex:1470: note: candidates are: std::complex<double>::complex(const std::complex<float>&)
/usr/include/c++/4.0.0/complex:1213: note:                 std::complex<double>::complex(double, double)
/usr/include/c++/4.0.0/complex:1155: note:                 std::complex<double>::complex(const std::complex<double>&)
scons: *** [build_darwin_i386/opt/Converters/PycArrayNP.os] Error 1
scons: building terminated because of errors.

The problem is the line
        new (storage) Target(get_source());
in implicit.hpp. 
However, It compiles fine when changing it to:
        Target tgt = get_source();
        new (storage) Target(tgt);
It might be better to use the default constructor and assign thereafter.

Maybe such a change needs to be made in the Boost.Python code. It will require, however, that the template parameter has a default ctor and assignment operator.

Cheers,
Ger




More information about the Cplusplus-sig mailing list