[C++-sig] Re: Re: Re: Re: Re: Re: Re: custom iterator object
Mike Rovner
mike at bindkey.com
Tue Nov 12 23:07:07 CET 2002
"David Abrahams" <dave at boost-consulting.com> wrote in message
news:ufzu6cz81.fsf at boost-consulting.com...
> > 1) I have an API:
> >
> > typedef int* T; // some type
> >
> > class CustomIter {
> > T First();
> > T Next();
> > };
> >
> > class Scheme {
> > CustomIter GetIter() const;
> > CustomIter GetIter1() const;
> > CustomIter GetIter2() const;
> > };
> >
> > 2) I want to expose Scheme to Python with 3 iterators
> > GetIter as __iter__, GetIter1 as attribute 'base', GetIter2 as attribute
> > 'top'
> > i.e. I want to be able to write:
> > s=Scheme()
> > for i in s: print i
> > for i in s.base: print i
> > for i in s.top: print i
>
> OK so far.
>
> > 3) In order to do that I created C++ wrap for CustomIter:
> >
> > class MyIter {
> > MyIter(CustomIter& init);
> > T next();
> > };
>
> Why? Why not just expose CustomIter?
If I understand correctly, I will NOT be able to use exposed CustomIter as
Python iterator.
Please correct me, if I'm wrong.
> You certainly have _me_ confused with all these levels of indirection.
> But I think I finally see what you're driving at, and it would
> obviously be helpful if there were a way to wrap function objects
> instead of just function pointers. Fortunately, I think there's a
> solution for your case:
Wonderful! It's working perfectly fine.
Thanks a lot!
Mike
PS. For a next dark (for me) corner I'm opening a new thread.
More information about the Cplusplus-sig
mailing list