Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!world!uunet!spool.mu.edu!caen!hellgate.utah.edu!csn!arrayb!wicklund From: wicklund@intellistor.com (Tom Wicklund) Newsgroups: comp.lang.c++ Subject: Re: How to define a List class Message-ID: <1991Jun19.151546.15605@intellistor.com> Date: 19 Jun 91 15:15:46 GMT References: <350001@hpgnd.grenoble.hp.com> <28539115.4D91@tct.com> <1991Jun11.172115.2804@intellistor.com> <285E7568.4E93@tct.com> Organization: Intellistor Lines: 36 In <285E7568.4E93@tct.com> chip@tct.com (Chip Salzenberg) writes: >According to wicklund@intellistor.com (Tom Wicklund): >>I think what's desired (and should be implementable) is a way to >>define a list class using templates and have the compiler be smart >>enough to create a single implementation for the list methods. >That can already be done with templates. Create a ListBase class with >all the interesting code. Then create List template in which >all member functions are inline. Presto. But the challenge is to do this without requiring inline functions. A list class shouldn't need to know anything about the objects which are being placed in the list except for size (depending on implementation) and the compiler can easily pass the size to a method if required. Unfortunately it requires better compiler technology than most current compilers. It should be possible to break template implementations down into various groups depending on the amount of code duplication required: 1. No duplication -- e.g. a list class using pointers to the object. 2. Needs object characteristics such as size (e.g. array of object), otherwise no duplication. 3. Needs specific methods (e.g. sorted array of object requires comparison), otherwise no duplication. At some point a function becomes complex enough that duplicate code is simpler than tracking all of the involved member functions. Unfortunately, avoiding duplicate code requires that the compiler have the template class implementation available when compiling any code using that class, which means either the compiler handles all source to the program at once or a very smart linker.