Boost logo

Boost Users :

Subject: Re: [Boost-users] [boost::python] iterator from member container
From: Dave Abrahams (dave_at_[hidden])
Date: 2011-01-17 20:03:12


On Mon, Jan 17, 2011 at 11:57 AM, Ralf Goertz
<R_Goertz_at_[hidden]> wrote:
> Is ist possible to have a class that has a map as member like
>
> struct Foo {
>        std::map<string,int> bar;
> };
>
> and then something like
>
> class_<Foo>("Foo")
>        .def("__iter__", iterator<std::map<string,int>());
>
> so that in python an object foo of type Foo can be used like this
>
> for i in foo:
>        <do something with the bar iterator i>
>
> ?

I think you might get a better answer from those on the python
C++-sig, but I think the problem with that code is that there's no
built-in conversion from pair<std::string const,int> to Python. You
can add your own converter and then it might work, though. There
might also be better ways to do this (e.g. check out the
map_indexing_suite).

HTH,

-- 
Dave Abrahams
BoostPro Computing
http://www.boostpro.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