Author: David Rasmussen
Date: 15:24:24 12/11/01
Go up one level in this thread
On December 11, 2001 at 17:49:24, Dann Corbit wrote: >On December 11, 2001 at 17:25:26, Roy Eassa wrote: >[snip] >>I was under the impression that templates were a new programming construct with >>C++ (i.e., they did not exist in any language before they were introduced into >>C++). Am I incorrect? > >The idea of Generic programming clearly predates templates. For instance, in >Ada, we had generic packages long before templates were invented. > >However, I broadly prefer the template implementation. Take a gander at the STL >complex template sometime, and see the incredible power of the template idea. I >can create a template that uses a big number class as easily as a float, double, >or long double complex type. > >Here are some templates I wrote which are freely available for any use: >A Kahan adder >(see >http://docs.sun.com/htmlcoll/coll.648.2/iso-8859-1/NUMCOMPGD/ncg_goldberg.html >under "Theorem 8 Kahan Summation Formula"): >ftp://cap.connx.com/pub/tournament_software/Kahan.Hpp > >Here is a statistics template that uses Kahan adders: >ftp://cap.connx.com/pub/tournament_software/STATS.HPP > >Here is a template for Skiplists: >ftp://cap.connx.com/pub/Public_CAP_Results/Brainy/SKIPLIST.HPP > >The nice thing about templates is not writing them {which can be a bit of a >pain} but rather in *using* them. > >For instance, if I want to make a dictionary from my skiplist, I just declare >one with string as the type and bam - instant dictionary. Any class that has a >greater than operator can be used by simply declaring it and we immediately have >a typesafe ADT container. I used it (for instance) to create a very compressed >version of EPD data that can be used for inquiry as to analyzed positions. It >can be just as useful for any sort of thing that needs O(log(n)) search time. > >I'm really enamored with templates. I really think that the way object-orientation, templates and generic programming (which is not just a buzzword), comes together in C++ is different and much more powerful than have been seen on similar devices in other languages. The "Containers of <T>" view of templates is too simplistic. Just take a look at the work of Andrei Alexandrescu in "Modern C++ Design - Design Patterns Applied". Reading that book made me wonder not only about what could be done in C++ today, but also what should be added to the language to make it even stronger. Some of his (amazing) stuff is just workarounds for missing features of the language that could easily be there. /David
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.