Re: [boost] [units] Interest in UDLs (e.g. _kg) for units?
From: Mathias Gaunard
To: boost@lists.boost.org Date: Mon, 25 Aug 2014 17:16:21 +0200 Subject: Re: [boost] [units] Interest in UDLs (e.g. _kg) for units? On 25/08/14 16:03, Sebastian Redl wrote: On 25 Aug 2014, at 13:24, Mathias Gaunard
wrote:
On 22/08/14 10:08, Curdeius Curdeius wrote:
Hi all,
I was wondering if there is any interest in adding User-Defined
Literals
(UDLs) to Boost.Units.
IMO, it could simplify some code and improve code readability in some cases. For example instead of writing (it's a somehow artificial example) 5.34 * si::milli * si::kilogram; 1234 * si::kilogram; one would write 5.34_g; 1234_kg;
Did you mean to write 5.34_g * si::milli; or 5.34_mg; ?
No, to get grams you need si::milli * si::kilogram. I assume the intention is that the _g suffix already includes that scaling - otherwise it’d be broken.
Sorry, I read that too fast. In any case the idea would be to get suffixes that include all prefix variants as well.
Yes, the idea is to include all the prefix variants as well, so for the mass, we will have: ..., _ng, _ug (?), _mg, _g, _kg, _Mg,_Gg, _Tg, ... And, the fact is, writing si::milli * si::kilogram is counterintuitive as you have just experienced on your own. Marek Kurdej -- Ph.D. candidate
-----Original Message----- From: Boost [mailto:boost-bounces@lists.boost.org] On Behalf Of Marek Kurdej Sent: 25 August 2014 17:31 To: Boost Developers' Mailing List Cc: mathias.gaunard@ens-lyon.org Subject: Re: [boost] [units] Interest in UDLs (e.g. _kg) for units?
From: Mathias Gaunard
To: boost@lists.boost.org Date: Mon, 25 Aug 2014 17:16:21 +0200 Subject: Re: [boost] [units] Interest in UDLs (e.g. _kg) for units? On 25/08/14 16:03, Sebastian Redl wrote: On 25 Aug 2014, at 13:24, Mathias Gaunard
wrote:
On 22/08/14 10:08, Curdeius Curdeius wrote:
Hi all,
I was wondering if there is any interest in adding User-Defined
Literals
(UDLs) to Boost.Units.
IMO, it could simplify some code and improve code readability in some cases. For example instead of writing (it's a somehow artificial example) 5.34 * si::milli * si::kilogram; 1234 * si::kilogram; one would write 5.34_g; 1234_kg;
Did you mean to write 5.34_g * si::milli; or 5.34_mg; ?
No, to get grams you need si::milli * si::kilogram. I assume the intention is that the _g suffix already includes that scaling - otherwise it’d be broken.
Sorry, I read that too fast. In any case the idea would be to get suffixes that include all prefix variants as well.
Yes, the idea is to include all the prefix variants as well, so for the mass, we will have: ..., _ng, _ug (?), _mg, _g, _kg, _Mg,_Gg, _Tg, ... And, the fact is, writing si::milli * si::kilogram is counterintuitive as you have just experienced on your own.
Looks much nicer! Will reduce the user resistance to using Boost.Units - it's a bit verbose for mere engineers and scientist's taste ;-) But have you implemented it yet? (and are there any hidden gotchas? - the proposed C++ time literals suffixes proved to be a can of worms :-( Paul --- Paul A. Bristow Prizet Farmhouse Kendal UK LA8 8AB +44 (0) 1539 561830
Paul A. Bristow skrev den 2014-08-26 19:13:
-----Original Message----- From: Boost [mailto:boost-bounces@lists.boost.org] On Behalf Of Marek Kurdej Sent: 25 August 2014 17:31 To: Boost Developers' Mailing List Cc: mathias.gaunard@ens-lyon.org Subject: Re: [boost] [units] Interest in UDLs (e.g. _kg) for units?
From: Mathias Gaunard
To: boost@lists.boost.org Date: Mon, 25 Aug 2014 17:16:21 +0200 Subject: Re: [boost] [units] Interest in UDLs (e.g. _kg) for units? On 25/08/14 16:03, Sebastian Redl wrote: On 25 Aug 2014, at 13:24, Mathias Gaunard
wrote:
On 22/08/14 10:08, Curdeius Curdeius wrote:
Hi all,
I was wondering if there is any interest in adding User-Defined
Literals
(UDLs) to Boost.Units.
IMO, it could simplify some code and improve code readability in some cases. For example instead of writing (it's a somehow artificial example) 5.34 * si::milli * si::kilogram; 1234 * si::kilogram; one would write 5.34_g; 1234_kg;
Did you mean to write 5.34_g * si::milli; or 5.34_mg; ?
No, to get grams you need si::milli * si::kilogram. I assume the intention is that the _g suffix already includes that scaling - otherwise it’d be broken.
Sorry, I read that too fast. In any case the idea would be to get suffixes that include all prefix variants as well.
Yes, the idea is to include all the prefix variants as well, so for the mass, we will have: ..., _ng, _ug (?), _mg, _g, _kg, _Mg,_Gg, _Tg, ... And, the fact is, writing si::milli * si::kilogram is counterintuitive as you have just experienced on your own.
Looks much nicer!
Will reduce the user resistance to using Boost.Units - it's a bit verbose for mere engineers and scientist's taste ;-)
But have you implemented it yet?
(and are there any hidden gotchas? - the proposed C++ time literals suffixes proved to be a can of worms :-(
One known problem is that the kg is the base unit, despite its prefix. That makes the higher units a bit odd. I have never ever seen Mg used, it would be called a ton (metric...). Then we have megatons, but never teragrams. Closing the can before anything bad happens... Bo Persson
Am Mittwoch, 27. August 2014, 11:01:46 schrieb Bo Persson:
Paul A. Bristow skrev den 2014-08-26 19:13:
-----Original Message----- From: Boost [mailto:boost-bounces@lists.boost.org] On Behalf Of Marek Kurdej Sent: 25 August 2014 17:31
Yes, the idea is to include all the prefix variants as well, so for the mass, we will have: ..., _ng, _ug (?), _mg, _g, _kg, _Mg,_Gg, _Tg, ... And, the fact is, writing si::milli * si::kilogram is counterintuitive as you have just experienced on your own.
Looks much nicer!
Yes, supporting variants most is definetely a must.
Will reduce the user resistance to using Boost.Units - it's a bit verbose for mere engineers and scientist's taste ;-)
But have you implemented it yet?
(and are there any hidden gotchas? - the proposed C++ time literals suffixes proved to be a can of worms :-(
One of the Boost goals is to find gotchas before they enter the standard. As long as this is an optional add-in, I'm all for it.
One known problem is that the kg is the base unit, despite its prefix. That makes the higher units a bit odd. I have never ever seen Mg used, it would be called a ton (metric...). Then we have megatons, but never teragrams.
Closing the can before anything bad happens...
Well, kilotons are also used. And we have km but not mm :-) Am Freitag, 22. August 2014, 10:08:34 schrieb Curdeius Curdeius:
The user would have to pull corresponding namespace (let's call it `udl`) to use it, for example
using namespace boost::units::systems::si::udl; // bring _kg, _km, ...
into scope
I think boost::units::systems::si:literals is a better namespace. Yours, Jürgen -- * Dipl.-Math. Jürgen Hunold ! * voice: ++49 4257 300 ! Fährstraße 1 * fax : ++49 4257 300 ! 31609 Balge/Sebbenhausen * jhunold@gmx.eu ! Germany
-----Original Message----- From: Boost [mailto:boost-bounces@lists.boost.org] On Behalf Of Jürgen Hunold Sent: 27 August 2014 11:09 To: boost@lists.boost.org Subject: Re: [boost] [units] Interest in UDLs (e.g. _kg) for units?
Closing the can before anything bad happens...
LOL!
Am Freitag, 22. August 2014, 10:08:34 schrieb Curdeius Curdeius:
The user would have to pull corresponding namespace (let's call it `udl`) to use it, for example
using namespace boost::units::systems::si::udl; // bring _kg, _km, ...
into scope
I think boost::units::systems::si:literals is a better namespace.
Strongly agree - one isn't going to type using boost::units::systems::si:literals; often? And megatons of Examples are needed ;-) Paul --- Paul A. Bristow Prizet Farmhouse Kendal UK LA8 8AB +44 (0) 1539 561830
participants (4)
-
Bo Persson
-
Jürgen Hunold
-
Marek Kurdej
-
Paul A. Bristow