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,9d303864ae4c70ad X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2004-04-13 21:50:28 PST Path: archiver1.google.com!news1.google.com!news.glorb.com!cyclone1.gnilink.net!spamkiller2.gnilink.net!gnilink.net!nwrdny01.gnilink.net.POSTED!0e8a908a!not-for-mail From: Hyman Rosen User-Agent: Mozilla Thunderbird 0.5 (Windows/20040207) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Expressing physical units (Was: Reprise: 'in out' parameters for functions) References: <5ad0dd8a.0404090512.15af2908@posting.google.com> <5ad0dd8a.0404100507.729d3577@posting.google.com> In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Date: Wed, 14 Apr 2004 04:50:27 GMT NNTP-Posting-Host: 68.237.226.219 X-Complaints-To: abuse@verizon.net X-Trace: nwrdny01.gnilink.net 1081918227 68.237.226.219 (Wed, 14 Apr 2004 00:50:27 EDT) NNTP-Posting-Date: Wed, 14 Apr 2004 00:50:27 EDT Xref: archiver1.google.com comp.lang.ada:7069 Date: 2004-04-14T04:50:27+00:00 List-Id: Dmitry A. Kazakov wrote: > 1. Shifted units, like Celsius degree. This can be done by adding an extra shift prameter. You would also need to describe the units system more thoroughly. The standard units can appear in positive or negative powers, but you obviously cannot do this with shifted units. > 2. Dealing with units unknown at compile time. How would you communicate > with a data base, or develop a gauge widget, or write a unit calculator? This requires a different solution. But that's OK. If many applications do not need this dynamic behavior, then they stand to benefit from the zero-overhead of the given solution. > How to write a unit I/O package? I demonstrated that in another post. You write a bunch of 'if' statements whose conditions depend on the template parameters, and they are all known at compile-time for a given unit. > 3. Dealing with multiple unit systems. You can add a scale factor template parameter for each dimension, and then they will be different types, so the compiler will prevent you from adding mm to cm, say. You can also code the conversions as templates. I suspect it's unwieldy and people would be just as happy to pick one unit system, but it could be done. > 5. How to handle logarithmic units and other non-linear scales? By specializing the templates for these units to do the appropriate operations. Ada does not have the concept of specialized templates, but C++ does. > 6. Container problem. Surely a vector, matrix etc of dimensioned values > should have a dimension. I don't see why, but that's certainly not a problem for C++. All of the standard container templates export the type of the object they hold as a named type called "value_type" so the units of the contained objects are available if needed. > 7. Any generic (template) solution would make everything based upon it also > generic. Modern C++ programmers see that as an opportunity, not a problem!