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-15 12:23:23 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!upp1.onvoy!onvoy.com!priapus.visi.com!news-out.visi.com!hermes.visi.com!uunet!ash.uu.net!spool0901.news.uu.net!spool0900.news.uu.net!reader0901.news.uu.net!not-for-mail Message-ID: <3CE2B5EF.2020409@mail.com> Date: Wed, 15 May 2002 15:24:31 -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> <3ce21f37$1@pull.gecm.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 2.3.3 (see http://www.nntpcache.org/) NNTP-Posting-Host: 204.253.250.10 X-Trace: 1021490600 reader1.ash.ops.us.uu.net 19581 204.253.250.10 Xref: archiver1.google.com comp.lang.ada:24123 Date: 2002-05-15T15:24:31-04:00 List-Id: Stephen Leake wrote: > The C++ template solution apparently computes and checks the Mass, > Distance, and Time values at _compile_ time, so there is no runtime > overhead. There is, in effect, the same combinatoric explosion of > types (actually operators in this case), but it is handled > automatically by the compiler, thru implicit instantiation (is that > the right term?). And only those operators that are actually used are > ever declared, and the _user_ only has to write the templates, not > the instantiations. Correct, in all respects. Furthermore, because the operations are so simple and can be declared inline, the explosion is only within the compiler (and perhaps the symbol table). The actual code will contain only simple arithmetic, just as if there were no units at all. In a real implementation, there would also be operators to allow multiplication and division by scalars, and scaled units are just handled by multiplication: typedef Unit Mass; const Mass gram = Mass(1); const Mass kilogram = 1000 * gram; const Mass pound = 2.2 * kilogram; Other posters have been mentioning fractional units. The C++ approach could accomodate this either by having the base unit be the least common multiple of all the roots (i.e., if you need meter^1/2 and meter^1/3 you could work in meter^1/6 and use powers of that) or by using rationals for the powers (so instead of Unit you can have Unit; the arithmetic can all still be done in the compiler, not at runtime).