Boost C++ Libraries: Ticket #9582: Boost.Units: conversion to double with prefixed unit https://svn.boost.org/trac10/ticket/9582 <p> A post to the Boost-users maillinglist suggested me to request this feature. </p> <p> 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. </p> <p> I think that adding this feature increases the symmetry in the use of Boost.Units, as I have emphasised in my code. </p> <p> 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. </p> <pre class="wiki">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&lt;length&gt; 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); </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/9582 Trac 1.4.3 Steven Watanabe Tue, 11 Mar 2014 00:42:44 GMT <link>https://svn.boost.org/trac10/ticket/9582#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9582#comment:1</guid> <description> <p> The first case is an /explicit/ conversion. The second would require an implicit conversion since there's no way to define an explicit conversion to double in C++03. It can be done in C++11, I believe. </p> </description> <category>Ticket</category> </item> <item> <author>richel@…</author> <pubDate>Sun, 16 Mar 2014 11:52:09 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9582#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9582#comment:2</guid> <description> <blockquote class="citation"> <blockquote> <p> It can be done in C++11, I believe. </p> </blockquote> </blockquote> <p> I checked with GCC 4.8.1 in C++1y mode: the unexpected behavior remains </p> </description> <category>Ticket</category> </item> </channel> </rss>