|
Boost Users : |
Subject: Re: [Boost-users] [units] Creating a velocity unit
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2013-02-21 13:41:10
AMDG
On 02/21/2013 10:25 AM, Ryan wrote:
> Thanks for the link it was helpful. I tried both methods and they both
> compiled. It seems we can use the simpler form of decltype because it
> provides perfect forwarding. Is this a correct interpretation?
>
Yes. The two are equivalent. decltype is a
bit nicer, as long as you know that you'll
only be using a compiler that supports it.
> Neither of these two typedef seems to behave as I expected. When creating
> a quantity with these typedefs I had to call them as a method to get the
> code to compile.
>
> quantity<si::velocity> a(2.3 * nautical_miles_per_hour1());
> quantity<si::velocity> b(2.4 * nautical_miles_per_hour2());
> quantity<si::velocity> c(2.5 * si::meters_per_second);
>
> Is there a way to get my type of nautical_miles_per_hour to behave like
> meters_per_second?
>
The difference is that meters_per_second is an object,
not a type:
static const si::velocity meters_per_second;
At this point, I prefer to use the type, because
I don't like having to come up with two different
names for the type and the global constant. I suppose
that it would also be possible to use only the
object, and use decltype whenever you need a type.
>
> //Provided for the Discussion
> using namespace boost::units;
> typedef metric::nautical_mile_base_unit::unit_type nautical_mile_unit;
> typedef metric::hour_base_unit::unit_type hour_unit;
>
> typedef decltype(nautical_mile_unit() / hour_unit())
> nautical_miles_per_hour1;
> typedef divide_typeof_helper<nautical_mile_unit, hour_unit>::type
> nautical_miles_per_hour2;
>
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