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=0.6 required=5.0 tests=BAYES_00,FROM_WORDY autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,571930b4ff0bc1ee X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-03-30 08:17:39 PST Path: supernews.google.com!sn-xit-02!supernews.com!news.gv.tsc.tdk.com!falcon.america.net!newspump.monmouth.com!newspeer.monmouth.com!news.maxwell.syr.edu!newspeer1.nac.net!news.stealth.net!newscon02.news.prodigy.com!newscon01.news.prodigy.com!prodigy.com!newscon07!newscon07!postmaster.news.prodigy.com!newssvr10-int.news.prodigy.com.POSTED!not-for-mail From: "Ken Garlington" Newsgroups: comp.lang.ada References: <3AC03CCE.70E3C2D5@mida.se> <3AC18DD1.EF25CE42@mida.se> <5mzw6.415$1H6.72722473@newssvr16.news.prodigy.com> <3AC2EB17.33AAEC0A@mida.se> <3AC46252.B7E54EA6@free.fr> Subject: Re: Compile time executed functions Organization: ex-FlashNet, now Prodigy X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 Message-ID: NNTP-Posting-Host: 65.65.210.42 X-Complaints-To: abuse@prodigy.net X-Trace: newssvr10-int.news.prodigy.com 985968797 6207069 65.65.210.42 (Fri, 30 Mar 2001 11:13:17 EST) NNTP-Posting-Date: Fri, 30 Mar 2001 11:13:17 EST Date: Fri, 30 Mar 2001 16:13:17 GMT Xref: supernews.google.com comp.lang.ada:6251 Date: 2001-03-30T16:13:17+00:00 List-Id: "Jean-Marc Bourguet" wrote in message news:3AC46252.B7E54EA6@free.fr... : Ken Garlington wrote: : : > Could you post an example of such a template, and what in the C++ standard : > you rely upon to guarantee compile-time calculations? : : First feature, things like : enum { foo = x+y*z; } : are valid as long as x, y and z value are known at compile time and have : to be evaluated at compile time. Isn't this usually resolvable as a constant by most Ada compilers? At least the ones I know will usually do so. More to the point, does the C++ standard _require_ that foo not generate any assembly instructions to be executed at run-time? If so, what does it say? : Second feature it is possible to provide "specialization" for template, : that is provide a different implementation when some template parameter : have some constant value. : : The first ensure that evaluation is made at compile time. The second : that it is possible to make some test. Looping is available with : recursion so finally you have a computationnally complete language at : compile time. It is painfull to write and even more painfull to use but : some like abusing the language... : : An example, how to compute factorial : : #include : : template : struct factorial { : enum { RET = factorial::RET*F }; : }; : : template <> : struct factorial<1> { : enum { RET = 1 }; : }; : : int main() { : std::cout << factorial<10>::RET << std::endl; : } Are you claiming that this resolves to a single constant value prior to execution? I don't see how... : > Also, does : > "compile-time" include "link-time", or are you not allowed to have anything : > in the table that uses addresses? : : As some C++ compilers do template instanciation at "link-time", I think : the answer is yes. I don't think we're talking about the same thing here... : -- Jean-Marc