Boost logo

Boost Users :

Subject: Re: [Boost-users] [units] Creating a velocity unit
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2013-02-21 22:50:44


AMDG

On 02/21/2013 01:56 PM, Ryan wrote:
>>
>> Yes, that's what I meant, but now that I see it written
>> out, it's wrong because decltype keeps the const qualifier.
>> You need the behavior of the non-standard typeof operator.
>> BOOST_TYPEOF should work.
>>
>
> quantity<BOOST_TYPEOF(nautical_mile)>(2.3 * nautical_mile);
>
> I tried this and it works. Is there a method, template or macro that lets
> me create the following two line like BOOST_UNITS_STATIC_CONSTANT?
>
> typedef metric::nautical_mile_base_unit::unit_type nautical_mile_unit;
> static const nautical_mile_unit nautical_mile;
>
> That way I don't have to create a name for the type and only use
> BOOST_TYPEOF if I need the type from the global constant.
>

There is no such macro (and it can't be done by
any other means). If you want one, there's nothing
stopping you from writing one yourself. Anything
that I could write would need to be generic enough
that it wouldn't save you anything. Also, I should
point out that you don't need the intermediate
typedef.
BOOST_UNITS_STATIC_CONSTANT(nautical_mile,
metric::nautical_mile_base_unit::unit_type);
will work just fine.

In Christ,
Steven Watanabe


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