Boost logo

Boost :

From: Paul A. Bristow (boost_at_[hidden])
Date: 2003-05-02 06:20:56


| Like with output operators for containers, etc., there are several existing
| approaches to this, as well. It certainly encourages experimentation.
| Perhaps a good solution could come from all of this.
|
| I intend to put it in the Sandbox, when it's ready, so people may take it
| for a spin. :)

I look forward to this [after my hols :-) ].
|
| As mentioned, the work on this predates the current Boost thread, as I
| experimented with a version about a year ago. When the issue has come up a
| few times, later, I've gone a little back to it. In summary, I've restarted
| several times.

| > It would be even nicer if input could be handled similarly, so we can ask
| the
| > user to input length, and correctly decode replies like 1.23 km, or 1.23
| um, or
| > even 1.23 inch, 1.23 yard for example.
|
| Yes, it would be possible, but it seems to then require a string as input,
| as "<identifier> <identifier>" (like "1.23 km") can't be used in C++ (unless
| you overload whitespace. ;) ).
|
| This would of course be a possibility, if that's what you suggest, e.g.:|
| length<double> value="1.23 km";|
| It would then have to decode this, before use.
| I'm already using Spirit for processing formatting strings for output, so it
| could be possible to use it for input, as well.
|
A string would seem OK. (Of course, decoding may get trickier: "1.234 km/s/s" to
"9.876 BThU/fortnight". And users will not doubt get M surprises when they get their 'm's and their M's confused ;-)
 
| The output formatting is decoupled from the type to be output, so anybody
| may write another output routine. To make it easy to use, it includes an
| output routine, which gives a lot of flexibility over the output. Like the
| stream operators, it uses a manipulator to set formatting.
|
| I've worked a lot on making the output formatting flexible, yet simple to
| use. The formatting is way more difficult than e.g. date/time formatting,
| because you have several ways of writing the quantity components. Therefore,
| if the following appears complex at first, please bear over with me until
| you see the output examples below it. Also, there's a default format, and
| any and all of the parameters to the format() function may be defaulted.
|
 Output: "1.23 kV (electric potential difference)"
|
| Nifty? ;)

Nifty Indeed!

But I have another suggestion which I find works very nicely, and that is to be able to dynamically chose the SI multiplier prefix so that the value is always between 1.0000 and 999.9999. So output of 978.6 m is 978.6 m but 1234 m is 1.234 km and 0.567 m is 567 mm.

And I have also combined this a stored uncertainty (perhaps a future system could use the Boost interval library for this) to only output significant decimal digits. This avoids the plague of misleading digits from almost all programs.
(Ideal for accountants - for example, value of Enron would have zero sig digs!)

| You may also treat angular_velocity as a synonym to frequency, by defining
| it this way. This is up to the library user, who may define any unit,
| prefix, etc.

I am sure an ideal solution must permit user-defined units.
|
| I'm also careful not to use partial specialisation, so it should work even
| on MSVC 6/7. :)

But is this becoming less important with the release of C++.net 2003 aka 7.11?which is rumoured to do nearly all the things it should. So if partial specialisation is the best/convenient solution, I would use it.

Good luck.

Paul

(Aside: What will Boost call the actual release C++.Net 2003? - as opposed to the 7.1 beta RC).

Paul A Bristow, Prizet Farmhouse, Kendal, Cumbria, LA8 8AB UK
+44 1539 561830 Mobile +44 7714 33 02 04
Mobile mailto:pabristow_at_[hidden]
mailto:pbristow_at_[hidden]
  


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk