Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!spool.mu.edu!mips!swrinde!elroy.jpl.nasa.gov!ncar!gatech!utkcs2!jamsun.ic.ornl.gov!mullens From: mullens@jamsun.ic.ornl.gov (James A. Mullens) Newsgroups: comp.lang.c++ Subject: Re: To template or not Message-ID: <1991Jun13.191619.17843@cs.utk.edu> Date: 13 Jun 91 19:16:19 GMT Article-I.D.: cs.1991Jun13.191619.17843 References: <1991Jun12.193426.8289@lynx.CS.ORST.EDU> <1991Jun13.143127.19044@kodak.kodak.com> Sender: usenet@cs.utk.edu (USENET News Poster) Organization: Univ of TN, Knoxville - CS Department Lines: 46 In article <1991Jun13.143127.19044@kodak.kodak.com>, cok@islsun.Kodak.COM (David Cok) writes: |> In article <1991Jun12.193426.8289@lynx.CS.ORST.EDU> budd@fog.cs.orst.edu (Tim Budd) writes: |> .. details of version of List class with a generic class doing the |> work and a template which derives from that class to provide |> type safety. |> > |> >Well, this works fine with ONE small exception. In order to test whether |> >something is already in the container, or remove it from the container, you |> >need some notion of what it means for two things to match. [much deleted] |> |> Not necessarily, the property of two things matching is part of the definition |> of the things, not of the list of things. To be specific -- and use the |> example below -- the property of equality of Cards should be a method of |> Cards, not on CardLists. [example code deleted] |> |> Now the only problem is that one |> can only make list's (with the template) of classes which have implemented |> operator== as the equality to use as a match. One could go a step further |> and supply a parameter which is a pointer to a member function which could |> be used as the test for equality (that was *could*, not *should*...) |> |> So by defining Card with the equality, CardList can be implemented simply as |> list without needing additional subclassing. |> There are 2 types of equality: (1) is this the same object and (2) does this object have the same value (as another object on the list)? My application needs only the first type of equality so I simply use the object's address (instead of a '=='). I also use strings to give many of my objects (which appear on lists) unique names, so I can use string equivalence. The strings aren't there just so I can perform this equality test in the list, it's just that the objects are created from text descriptions of the objects (at run time) and the names are required by the descriptions. My whole approach to implementing lists is different. I have defined some m4 (Unix macro processor) macros which will create the appropriate .c and .h files for a list of a particular type of object. The make utility is used to update the .c and .h files whenever the macro definition changes. This is easy to implement and maintain. I intend to use templates later, but not because there is anything wrong with the way I'm doing it now. jim mullens oak ridge national laboratory mullens@jamsun.ic.ornl.gov