Subject: [Boost-bugs] [Boost C++ Libraries] #9582: Boost.Units: conversion to double with prefixed unit
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2014-01-16 08:59:23
#9582: Boost.Units: conversion to double with prefixed unit
-------------------------------------+-----------------------------
Reporter: richel@⦠| Owner: matthiasschabel
Type: Feature Requests | Status: new
Milestone: To Be Determined | Component: units
Version: Boost 1.54.0 | Severity: Cosmetic
Keywords: Units conversion prefix |
-------------------------------------+-----------------------------
A post to the Boost-users maillinglist suggested me to request this
feature.
In the code below, I convert a double that is known to be in millimeters
to a unit and back again. The latter fails, where it works as expected for
meters.
I think that adding this feature increases the symmetry in the use of
Boost.Units, as I have emphasised in my code.
I am aware of the great care the Boost.Units developers have in
maintaining type-safety, so it might be that I am unaware of code
compiling that shouldn't would this request be acknowledged.
{{{
using boost::units::conversion_factor;
using boost::units::quantity;
using boost::units::si::length;
using boost::units::si::meter;
using boost::units::si::milli;
typedef quantity<length> Length;
//This value is read from file
const double x_in_mm = 1.0;
//Add units
const Length x(x_in_mm * (milli * meter)); //Brackets added for emphasis
const double x_again_in_m = x / meter; //Works
const double x_again_in_mm {
x / (milli * meter) //Same brackets as at emphasis
}; //Why doesn't this?
assert(x_in_mm == x_again_in_mm);
}}}
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/9582> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:15 UTC