iterator design help
From: Rex_chaos (rex_chaos_at_21cn.com)
Date: 10/20/03
- Next message: Sonoman: "Re: C++ and databases question"
- Previous message: Julián Albo: "Re: C vs Perl"
- Next in thread: Victor Bazarov: "Re: iterator design help"
- Reply: Victor Bazarov: "Re: iterator design help"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 20 Oct 2003 08:31:05 -0700
Hi there,
I am writing an iterator for a container. Just like a typical
iterator,
template <typename ADT>
class MyIter
{
...
MyContainer<ADT>& refc;
public:
MyIter(MyContainer<ADT>& cont) :refc(a) {...}
MyIter& begin() {...; return *this;}
MyIter& end() {...; return *this;}
MyIter& operator++() {...; return *this;}
...
};
While MyIter is applied to a template algorithm like std::transform,
the copy constructor will be actived because of the reference to cont.
It lowers effeciency a lot. Maybe I should use a pointer as instead
for speed purpose
...
MyContainer<ADT>* refc;
public:
MyIter(MyContainer<ADT>& cont) :refc(a) {...}
...
However, it is another problem. Suppose the container passed to the
iterator has been released, refc will then become an invalid pointer
!!! I can't release the pointer (refc) in the destructor because I
don't know if any object own the container.
- Next message: Sonoman: "Re: C++ and databases question"
- Previous message: Julián Albo: "Re: C vs Perl"
- Next in thread: Victor Bazarov: "Re: iterator design help"
- Reply: Victor Bazarov: "Re: iterator design help"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|