From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,103b407e8b68350b X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-01-23 08:28:25 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!lnsnews.lns.cornell.edu!news.litech.org!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newshosting.com!news-xfer1.atl.newshosting.com!uunet!dca.uu.net!ash.uu.net!spool0902.news.uu.net!not-for-mail Date: Thu, 23 Jan 2003 11:27:46 -0500 From: Hyman Rosen User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.3b) Gecko/20030116 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Anybody in US using ADA ? One silly idea.. References: <1042743579.1165@master.nyc.kbcfp.com> <1042824191.538184@master.nyc.kbcfp.com> <_VkW9.266404$FT6.43771824@news4.srv.hcvlny.cv.net> In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Organization: KBC Financial Products Message-ID: <1043339266.922562@master.nyc.kbcfp.com> Cache-Post-Path: master.nyc.kbcfp.com!unknown@nightcrawler.nyc.kbcfp.com X-Cache: nntpcache 3.0.1 (see http://www.nntpcache.org/) NNTP-Posting-Host: 204.253.250.10 X-Trace: 1043339268 26191 204.253.250.10 Xref: archiver1.google.com comp.lang.ada:33380 Date: 2003-01-23T11:27:46-05:00 List-Id: Dmitry A. Kazakov wrote: > with templates you never know if the actual type is "Hashable", > until you instantiate all functions using all methods of "Hashable". You also don't *care* if the actual type supports all methods of "Hashable" if you don't use them! > And even so, nobody can say whether these methods really comprise > a "Hashable" type or they just have similar names and the profiles > appropriate to go through the compiler. Nobody can say whether something that inherits from "Hashable" has implemented the methods correctly. For example, I could have a type that I think will never actually go into a hashtable but must be "Hashable" for some reason, so I implement its hashing method to just return zero. Then someone decides to put it into a table after all... By the way, you might find the following link interetsing. It's a recursive descent parsing system designed using C++ template metaprogramming. There are a few places where the code uses inheritance and virtual dispatch, but only to get around C++'s limitations in naming a type based on an expression. The author complains about how virtual methods get in the way of efficient code. The problem is that we want to abe able to say 'declare variable = expression' and have the type of the variable be the type of the expression. Because C++ instantiates generics automatically, and as you saw in the Unit code I posted, can synthesize return types, it's difficult to examine an expression and write out its type, even though the compiler has no trouble doing so. To work around this, you can create a placeholder type which can hold any kind of expression of interest, but then this forces you into dispatch mode instead of generic mode. It's especially annoying because all the facilities are already present in the language - if you declare template void func(const T &) { }, and call func(expression), the compiler deduces the expression type, and it's available inside func. But there's no way to get it out, that is, to use the same type deduction to declare a variable of the appropriate type, outside of the function.