From: Christophe de V. <cde...@al...> - 2003-05-26 12:40:29
|
=2D----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Le Vendredi 23 Mai 2003 18:57, and...@am... a =E9crit : > > In other words, I am agreeing with Murray that it is a separate > class. Me too (that's what I'm saying in the part of the message you didn't quote = :-) So I started implementing something this way. I have the following classes : ChildrenList, ChildrenList::iterator and ChildrenList::const_iterator The API is STL-like : iterator ChildrenList::begin(); const_iterator ChildrenList::begin() const; iterator ChildrenList::end(); const_iterator ChildrenList::end() const; on the different iterators we have operators ++(), ++(int), =3D=3D(), !=3D(= ), *()=20 and ->(). I plan to add rbegin() and rend() and ad-hoc iterators. Node::get_children() returns a reference to a ChildrenList which is an=20 attribute of Node initialised in constructor. One problem I faced is the type return by iterator::operator*(). I first wanted to return a Node &. It is, I think, more logical, and avoid= =20 writing things like (*iter)->do_something(). However this change the use of dynamic_cast to 'test' the type of node. If = the=20 cast fail we have an exception instead of just returning a null pointer. Moreover this will make a bit heavy the switching from a version to another= =20 (but this may be acceptable from a 1.0 to 2.0 version upgrade). So the question is : What do you expect as a return type for=20 Node::ChildrenList::iterator::operator*() ? remark: One alternative I thought of is to have : Node * operator*() and Node * operator->() So we can both avoid complicating use of dynamic_cast and writing stuffs li= ke=20 (*iter)->do_something(). But I don't think this is a very standard behavior and would prefer not to = do=20 that. Regards, Christophe =2D----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (GNU/Linux) iD8DBQE+0gs0B+sU3TyOQjARAlh8AJ0fw41qtK1QtMxB1sY0mmjmVvxAegCg4SgB PYyxAMYlOId6SQiJz/aSl5Q=3D =3DuUIR =2D----END PGP SIGNATURE----- |