Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!snorkelwacker.mit.edu!bloom-beacon!eru!hagbard!sunic!lth.se!newsuser From: dag@control.lth.se (Dag Bruck) Newsgroups: comp.lang.c++ Subject: Re: Common data structures Keywords: list, data structures, c++ Message-ID: <1991Jun11.061402.21934@lth.se> Date: 11 Jun 91 06:14:02 GMT References: <1991Jun10.200429.26713@lynx.CS.ORST.EDU> Sender: newsuser@lth.se (LTH network news server) Organization: Department of Automatic Control, Lund, Sweden Lines: 56 I agree: writing a list package is a non-trivial task, and we should encourage anyone who's willing to share his/her interpretation of what it should look like. Here are three additional suggestions: 1. Member of multiple lists In most list packages an element can be the member of only one list at a time. For me and my colleagues this is quite unacceptable. We often keep a large group objects in a "master" list and then create temporary sub-lists for some particular processing task. The straigh-forward use of a base class "Link" which all other classes are derived from won't work; some sort of indirection is needed. 2. Constant objects It should be possible to declare a list of `const' objects. This may not be easy depending on how you use the macro processor. My own list package does not handle this case gracefully. A `typedef' may help: typedef const T cT; List(cT) clist; (Note that I assume that a real template implementation handles this case without any additional typedef.) 3. Const compatibility If I have a list of Foo objects, I would like to pass it to a function than takes a list of `const Foo' objects: typedef const Foo cFoo; void f(const List(Foo) x) { .... } void g(List(cFoo) x) { .... } void h() { List(Foo) fl; f(fl); // no problem g(fl); // hmmm } In function h(), `fl' is a mutable list of mutable Foo objects. There is no problem calling f(), which takes a constant list of mutable objects. The difficulty is to explain to the compiler that a list of non-mutable objects is compatible with a list of mutable objects. Comments would be appreciated. Dag Bruck -- Department of Automatic Control E-mail: dag@control.lth.se Lund Institute of Technology P. O. Box 118 Phone: +46 46-104287 S-221 00 Lund, SWEDEN Fax: +46 46-138118