Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!lll-winken!aunro!alberta!ubc-cs!uw-beaver!fluke!ssc-vax!dmg From: dmg@ssc-vax (David M Geary) Newsgroups: comp.lang.c++ Subject: Re: How to define a List class Message-ID: <4173@ssc-bee.ssc-vax.UUCP> Date: 21 Jun 91 17:31:27 GMT References: <285E7568.4E93@tct.com> <1991Jun19.151546.15605@intellistor.com> <1991Jun20.220432.955@lia> Sender: news@ssc-vax.UUCP Reply-To: dmg@ssc-vax.UUCP (David M Geary) Organization: Boeing Aerospace & Electronics Lines: 49 In article <1991Jun20.220432.955@lia> jgro@lia.com (Jeremy Grodberg) writes: ]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 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Why? ]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. ] Oh, how true. This is deja vu - reminds me of those refusing to use functions years back, because the overhead of a function call was more than a goto... -- |~~~~~~~~~~ David Geary, Boeing Aerospace, Seattle, WA. ~~~~~~~~~~| |-----------------------------------------------------------------------------| |~~~~~~ Seattle: America's most attractive city... to the *jetstream* ~~~~~~| |-----------------------------------------------------------------------------|