[C++-sig] Re: Re: Re: Re: custom iterator object

David Abrahams dave at boost-consulting.com
Tue Nov 12 04:43:52 CET 2002


"Mike Rovner" <mike at bindkey.com> writes:

> "David Abrahams" <dave at boost-consulting.com> wrote in message
> news:un0ofy3i8.fsf at boost-consulting.com...
>
>> > How can I pass 'this' from wrapping class?
>>
>>
>> Didn't I write this?
>>
>> > >   Remember that the iterator's own __iter__ method can be
>> > >   implemented by wrapping this C++ function:
>> > >
>> > >     object identity(object x)  { return x; }
>>
>> Did I leave something out? You can use:
>>
>>     .def("__iter__", identity)
>>
>> inside your iterator wrapper class. Does that make it clear? Or are
>
> I'm really sorry not making myself clear.
> I have no problem wrapping my itereator class.
>
>> you really asking something else?
>
> I have problem _creating that iterator_ from another object.
> For creating an iterator I have to call member function.
> For calling it I have to have a C++ object reference, i.e.
>
> Scheme& s;
> MyIter s.*pm();
>
> Now I'm trying to wrap that class (that shall return an iterator):
>
>   class_<Scheme>("Scheme")
>     .def("__iter__", mem_fun_ref(&Scheme::GetIter))

Why aren't you just using

     .def("__iter__", &Scheme::GetIter)

here? What is mem_fun_ref supposed to buy you?

-- 
                       David Abrahams
   dave at boost-consulting.com * http://www.boost-consulting.com
Boost support, enhancements, training, and commercial distribution





More information about the Cplusplus-sig mailing list