Boost logo

Boost :

Subject: Re: [boost] [python] non-standard iteration / wrapping member function return value
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2013-06-04 13:47:55


AMDG

On 06/04/2013 10:07 AM, Matus Chochlik wrote:
> Hi,
>
> I'm stuck at trying to make python bindings for a set of classes that use a
> non-c++-standard iteration protocol. I've made a minimal example of what
> I'm trying to do:
>
> the python-ized classes look in essence like this:
>
> //-------------------------------------------------------------
> class int_range;
>
> <snip>
>
> class _py_int_range;
>
> class_<_py_int_range>("_py_int_range", init<const int_range&>())
> .def("__iter__", &_py_int_range::iter)
> ;
> //-------------------------------------------------------------
>
> the problem is that when I register range_maker as follows...
>
> //-------------------------------------------------------------
> class_<range_maker>("range_maker")
> .def("make", &range_maker::make)
> ;
> //-------------------------------------------------------------
>
> ... it compiles but (obviously) fails in python at run-time because
> range_maker::make returns int_range and not _py_int_range.
>
> <snip>
>

It would probably work better if you adapted
int_range directly instead of creating a separate
class for python. (Def can take a function pointer.
You don't have to use a member function)

In Christ,
Steven Watanabe


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk