Re: user-defined iterator
On Jun 15, 5:02 pm, "Victor Bazarov" <v.Abaza...@comAcast.net> wrote:
vasili wrote:
I have a simple issue.
:-)
It takes a complicated language to solve complicated
problems:-).
I defined a custom container, that encloses a std::list, which in turn
holds objects that are a simple abstraction of a six position array.
Now, i would like to serialize the whole newly-defined container, in
order to copy the contents to another array. So i thought to define an
iterator which represented a "pointer" to the container's data. But,
when i feed these iterators to std::copy the compiler complains about
a lot of types which are defined when a std::iterator is instanced.
Since you want to use standard algorithm, it _may_ require that you
specialize 'iterator_traits' for your custom iterator.
He must do something to ensure that iterator_traits<Iterator>
contains the proper typedefs. The generic implementation of
this template supposes that there are corresponding typedef's in
the Iterator class; the standard library also contains a partial
specialization for pointers (since pointers obviously don't
contain the necessary typedef's). He can thus either provide a
custom specialization, with the necessary typedef's, or put the
typedef's in his class. The latter is the classical solution,
and the standard offers a class template, std::iterator, to help
here. All he has to do is have his iterator derive (publicly)
from the appropriate instantiation of std::iterator, and it
should suffice.
--
James Kanze (Gabi Software) email: james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34