Boost logo

Boost Users :

Subject: Re: [Boost-users] [Units] Name a unit for output
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2017-12-20 04:04:59


AMDG

On 12/19/2017 05:38 PM, Santiago Ospina via Boost-users wrote:
> I would like to know if there is an equivalent for giving a name and a symbol given a unit in boost::units (maybe scaled from another one).
>
> I know the example of naming base units, however, it would imply I'd have to create a system and a conversion for every unit I want to implement.
>
> I tried to write it directly from the scaled version, like this:
>
> template<>
> struct scale_minute<60, static_rational<1> >
> {
> static const long base = 60;
> typedef Detail::static_rational<1> exponent;
> typedef double value_type;
> static value_type value() { return(60); }
> static std::string name() { return("minute"); }
> static std::string symbol() { return("m"); }
> };
>
> however, it is adding my scaled name plus my base name (say the base name is “s” which stands for seconds, then it would print “m” + "s”).
>
> Any idea how to overcome with that?
>

try:
#include <boost/units/base_units/metric/minute.hpp>
using minutes = boost::units::metric::minute_base_unit::unit_type;

You should be able to use the same method of specializing
base_unit_info.

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