Boost logo

Boost Users :

Subject: Re: [Boost-users] [units] Dimensionless? expecting length+length
From: Michael Powell (mwpowellhtx_at_[hidden])
Date: 2015-08-11 07:49:51


On Mon, Aug 10, 2015 at 10:50 PM, Gavin Lambert <gavinl_at_[hidden]> wrote:
> 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_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net