A C++ iterator adapter which wraps and hides an inner iterator and converts the iterated type

前端 未结 7 1592
盖世英雄少女心
盖世英雄少女心 2020-12-09 04:25

Having toyed with this I suspect it isn\'t remotely possible, but I thought I\'d ask the experts. I have the following C++ code:

class IInterface
{
    virtual vo         


        
7条回答
  •  渐次进展
    2020-12-09 05:26

    I see no reason why you can't implement this exactly as you've laid it out... am I missing something?

    To clarify, you'll need to put some kind of accessor methods on your Container class. They can be private and you can declare MagicIterator as a friend, if you feel that's the best way to encapsulate it, but I'd expose them directly. These accessor methods would use a normal STL iterator inside Container and perform the conversion to IInterface. Thus the iterating would actually be done with the Container's accessor methods and MagicIterator would just be a kind of proxy object to make it easier. To make it reentrant, you could have the MagicIterator pass in some kind of ID to look up the STL iterator inside Container, or you could actually have it pass in the STL iterator as a void *.

提交回复
热议问题