Renato Araujo wrote:
Hi guys,
I'm trying use the "implicitly_convertible" to specify to boost.python
the possible conversions for every type, but I start get some errors
in my functions call because, the boost.python accept conversions in
more then one level. Like in this code:
The boost.python allow me to call the function "value" passing "int"
as argument type. Because "int" is implicitly convertible to "X" and
"X" is implicitly convertible to "Y".
This make a mess in my functions because boost try converter the
values before try other functions and call the wrong functions.
I would like to know if is possible to avoid this level of conversion
and tell to boost.python only try the direct conversion, because this
make the functions call slower then normal calls, and some times cause
a lot of problems in my classes.
-------------------------------
#include <boost/python/class.hpp>
#include <boost/python/implicit.hpp>
#include <boost/python/module.hpp>
#include <boost/python/def.hpp>
using namespace boost::python;
struct X
{
X(int x) : v(x) {}
int v;
};
struct Y
{
Y(const X& w) : v(w.v) {}
int v;
};
int value(Y const& x)
{
return x.v;
}
BOOST_PYTHON_MODULE(implicit_ext)
{
def("value", value);
class_<X>("X",
init<int>())
;
class_<Y>("Y",
init<const X&>())
;
implicitly_convertible<X,Y>();
implicitly_convertible<int,X>();
}
---------------------------------------
Hi,
I'm in a rather elliptical orbit at the moment but should be coming back
around soon. I'll have a look at this: if we're going to attempt to
fix overloading, we might as well try to make boost.python obey the c++
rule of 'no more than 1 user-defined conversion in a row'.
Renato, the overloading stuff mentioned by Hans is in a thread titled
"Implementation of proper overload resolution" on this list.
-t
_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig