Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!olivea!uunet!fernwood!lia!jgro From: jgro@lia (Jeremy Grodberg) Newsgroups: comp.lang.c++ Subject: Re: How to define a List class Message-ID: <1991Jun20.220432.955@lia> Date: 20 Jun 91 22:04:32 GMT References: <350001@hpgnd.grenoble.hp.com> <28539115.4D91@tct.com> <1991Jun11.172115.2804@intellistor.com> <285E7568.4E93@tct.com> <1991Jun19.151546.15605@intellistor.com> Reply-To: jgro@lia.com (Jeremy Grodberg) Lines: 40 In article <1991Jun19.151546.15605@intellistor.com> wicklund@intellistor.com (Tom Wicklund) writes: >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. This is not entirely true. The list class needs to know the type of object that is being added and extracted. Templates allow for compile-time checking, whereas other methods require run-time checking. Yes, it is a little inelegant to duplicate the code, but it is not much code to duplicate. We aren't using computers with 4 K of core and which execute a few thousand instructions per second anymore. I'm getting tired of people complaining about implementations which waste a few hundred bytes of code without ackowledging the benefit of increased reliability and decreased programming time. In many cases, templates even produce more time-efficient code. Don't get me wrong; I'd love to have a solution which provides all the benefits of templates without the extra code, but in the mean time, I think the cost is well worth it. -- Jeremy Grodberg "Show me a new widget that's bug-free, and I'll show jgro@lia.com you something that's been through several releases."