On Mon, Aug 10, 2015 at 10:50 PM, Gavin Lambert
On 11/08/2015 14:12, Michael wrote:
You can, but it's not necessary. Simply assign value * milli * seconds
to a variable of quantity<time> (aka Time) and it automatically converts everything to seconds (since that's the base unit of "time"). This prevents other operations getting confused by scaled units, which happens when you use "auto" because it skips this conversion.
Ah I gotcha. So the prevailing wisdom is auto auto auto, except when quantities and prefixed unit conversions are concerned.
I'm not sure about "prevailing wisdom". I don't use auto anywhere with Boost.Units (I use explicit types as mentioned above instead). But then, most of my usage of Boost.Units was written in the dark ages (C++03 compiler).
This does work. const quantity<time> value_(value * milli * seconds); Thank you...
TBH your code seems a little too auto-happy to me -- I wouldn't have defined things like "two" or "milliseconds" or "gValue" or the static_casts and would have just written the values inline instead, as I think it's sufficiently clear that way. But that's just a coding style thing (the compiler should be smart enough to generate the same code either way) and if you think that makes it clearer for you then go for it. That's probably a more reasonable place to use "auto", for things that aren't quantities.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users