Boost logo

Boost Users :

From: David Abrahams (dave_at_[hidden])
Date: 2002-11-03 17:15:40


"jefflholle" <jeff.holle_at_[hidden]> writes:

> I've just started experimenting with version 2 of boost.python.
>
> In iterator.cpp, a std::list is wrapped using following code:
>
> typedef std::list<int> list_int;
> void push_back(list_int& x, int y)
> {
> x.push_back(y);
> }
>
> int back(list_int& x)
> {
> return x.back();
> }
> .
> .
> .
> class_<list_int>("list_int")
> .def("push_back", push_back)
> .def("back", back)
> .def("__iter__", iterator<list_int>())
> ;
>
> Is it possible to use the container methods instead of user defined
> functions?

Sure. But not for the standard containers, because you can't portably
take the address of a standard library (member) function. The
implementation is allowed to add overloads and default arguments, so
there's no way to reliably identify the function you're looking for.

> I've tried the code:
> class_<list_int>("list_int")
> .def("push_back", &list_int::push_back)
> .def("back", &list_int::back)
> .def("__iter__", iterator<list_int>())
> ;
> This doesn't work.
>
> Am what I'm tried to do possible?

Yes.

> If so, how?

Write your own container, with predictable function signatures ;-)

-- 
                    David Abrahams
dave_at_[hidden] * http://www.boost-consulting.com

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net