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,1dd28d5040ded1f8 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-05-22 09:29:40 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!bloom-beacon.mit.edu!nycmny1-snh1.gtei.net!news.gtei.net!news-out.visi.com!hermes.visi.com!uunet!ash.uu.net!spool0900.news.uu.net!reader0902.news.uu.net!not-for-mail Message-ID: <3CEBC7C9.10604@mail.com> Date: Wed, 22 May 2002 12:31:05 -0400 From: Hyman Rosen User-Agent: Mozilla/5.0 (Windows; U; WinNT4.0; en-US; rv:1.0rc2) Gecko/20020510 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Announce: Grace project site operational References: <4519e058.0205140718.3ddb1b2a@posting.google.com> <3CE15D0A.3050100@mail.com> <2s44eu0fm4g6606h9p4stb1b5oc0nmg5u8@4ax.com> <3CE2A946.5030808@mail.com> <3CE40B8E.70102@mail.com> <3ucneuoh5kgemqpoq85ts5v7lolnk760bn@4ax.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Organization: KBC Financial Products Cache-Post-Path: master.nyc.kbcfp.com!unknown@mosquito.nyc.kbcfp.com X-Cache: nntpcache 3.0.1 (see http://www.nntpcache.org/) NNTP-Posting-Host: 204.253.250.10 X-Trace: 1022084979 reader2.ash.ops.us.uu.net 12339 204.253.250.10 Xref: archiver1.google.com comp.lang.ada:24530 Date: 2002-05-22T12:31:05-04:00 List-Id: Dmitry A. Kazakov wrote: > I did not claimed that C++ is untyped. I claimed that the formal > template parameters are untyped in the sense that you cannot say: > > template > This requirement cannot be made a part of the contract. The contract > is as simple as "any type that makes macro expansion a valid program". Not macro expansion, but substantially correct otherwise. > It is not much better than: #define private public. I don't understand what this means. If you do this inconsistently, you are violating the rules of the language, and the result is undefined behavior. I cannot imagine how this is related to templates. > So far the result > remains a valid programs it is fine! That actual has or has not plus > will be checked in C++ only after substitution. One need body to check > that! Consider that somebody has instantiated your template, but did > not use the bodies where + is used. No error, though the contract is > broken. Well, after 10 years or so, somebody would try to use that > bodies and run at misterious errors in the code which is supposed to > be safe. Once they try to use the body, the code will fail to compile. This will not be unsafe in the sense of causing the program to behave improperly, since it will not build at all. Meanwhile, there will have been ten years of perfectly good and valid use. > In Ada at least one can write: > generic > type Thing is new Field with private; -- Field has "+" In C++, an expression like a + b can find the meaning of it's "+" operator in many ways. There can be free functions, member functions, and conversions involved, and circumstances dictate using various approaches. Therefore, it is difficult, and likely useless, for a template writer to specify some definite origin for the operator. The only purpose will be to limit the utility of the template. Nevertheless, some people (like you!) want this kind of checking anyway, and it is possible to code the checks in C++, through a process called "concept checking". This uses template metaprogramming to cause templates to fail to compile when instantiated with types that fail the concept check.