[units] Interest in UDLs (e.g. _kg) for units?
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; I propose to add this feature for compatible compilers (where BOOST_NO_CXX11_USER_DEFINED_LITERALS is not defined). 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 What are your feelings about it? In the first place, I would go for `operator ""` taking as arguments `unsigned long long` and `long double`. Later, one could think about the one taking a `const char *` argument which would provide a quantity with an underlying type of arbitrary precision (like boost::multiprecision::cpp_int). Regards, Marek Kurdej -- Ph.D. candidate
On August 22, 2014 4:08:34 AM EDT, Curdeius Curdeius
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;
That would be much more readable, so the idea has merit. Usability, compile-time overhead, diagnostics, etc. would be factors in evaluating the result. ___ Rob (Sent from my portable computation engine)
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; ?
On 25 Aug 2014, at 13:24, Mathias Gaunard
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. Sebastian
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.
It might be nice to support non-abbreviated varations: _milligram, _kiloton, _megabyte, etc. As an aside, there is a "derived" unit for just grams defined in there somewhere, maybe as part of the CGS subsystem? ----- Original Message -----
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;
I propose to add this feature for compatible compilers (where BOOST_NO_CXX11_USER_DEFINED_LITERALS is not defined). 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
What are your feelings about it?
In the first place, I would go for `operator ""` taking as arguments `unsigned long long` and `long double`. Later, one could think about the one taking a `const char *` argument which would provide a quantity with an underlying type of arbitrary precision (like boost::multiprecision::cpp_int).
Regards,
Marek Kurdej -- Ph.D. candidate
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
participants (5)
-
Curdeius Curdeius
-
Erik Erlandson
-
Mathias Gaunard
-
Rob Stewart
-
Sebastian Redl