[C++-sig] What if a Python override returns several values?
Matthias Baas
baas at ira.uka.de
Thu Sep 14 16:44:19 CEST 2006
David Abrahams wrote:
>> void g(int& a, int& b) {
>> boost::python::tuple tup = this->get_override("g")();
>> a = ...extract an int from tup[0]...
>> b = ...extract an int from tup[1]...
>> }
>>
>> [...]
>> TypeError: No registered converter was able to extract a C++ reference
>> to type boost::python::tuple from this Python object of type tuple
>[...]
> Okay. Does it work if you don't use copy-initialization?
Now that you mention it I actually have to confess that I was not aware
that this could make a difference. My original code rather looked like this:
boost::python::tuple tup;
tup = this->get_override("g")();
And this results in the above TypeError exception.
I only noticed now that the following code actually does work (sorry):
boost::python::tuple tup = this->get_override("g")();
I don't suppose this difference is intentional, is it?
Unfortunately, it's not that trivial for me to get to the latter version
as the code I'm using is not written manually but is generated by a tool
which separates the declaration of variables from their usage.
> boost::python::tuple tup(this->get_override("g")());
No, this results in the following compile error:
call of overloaded `tuple(boost::python::detail::method_result)' is
ambiguous
candidates are:
boost::python::tuple::tuple(const boost::python::tuple&)
boost::python::tuple::tuple(boost::python::detail::new_non_null_reference_t*)
boost::python::tuple::tuple(boost::python::detail::new_reference_t*)
boost::python::tuple::tuple(boost::python::detail::borrowed_reference_t*)
boost::python::tuple::tuple(const T&) [with T =
boost::python::detail::method_result]
> boost::python::object t = this->get_override("g")();
> boost::python::tuple tup(t);
Yes, this works (see above).
> what about:
>
> boost::python::tuple tup
> = this->get_override("g")().as<boost::python::tuple>();
Yes (what's this anyway? I didn't see that in the reference manual).
- Matthias -
More information about the Cplusplus-sig
mailing list