Boost C++ Libraries: Ticket #6872: units/io.hpp: autoprefix_norm_impl<> should resolve to no-op for unsigned built-in types https://svn.boost.org/trac10/ticket/6872 <p> The code </p> <blockquote> <p> using namespace boost::units; const quantity&lt;si::length, int&gt; boa = 5 * si::meters; std::cout &lt;&lt; boa &lt;&lt; std::endl; </p> </blockquote> <p> prints "5 m", as expected, yet </p> <blockquote> <p> using namespace boost::units; const quantity&lt;si::length, unsigned int&gt; boa = 5 * si::meters; std::cout &lt;&lt; boa &lt;&lt; std::endl; </p> </blockquote> <p> fails to compile due to the std::abs call being ambiguous in io.hpp: template&lt;class T&gt; struct autoprefix_norm_impl&lt;T, true&gt; { </p> <blockquote> <p> typedef double type; static double call(const T&amp; arg) { return std::abs(arg); } </p> </blockquote> <p> }; </p> <p> There should be a specialization resolving to a no-op (just return the arg) for unsigned types. </p> <p> A (probably slightly heavier) user-side workaround possible one can use is to forcibly define the missing std::abs to be a no-op as follows: </p> <p> namespace std { </p> <blockquote> <p> template&lt;typename Unsigned&gt; typename boost::enable_if&lt;boost::is_unsigned&lt;Unsigned&gt;, Unsigned&gt;::type </p> <blockquote> <p> abs(const Unsigned&amp; x) </p> </blockquote> <p> { </p> <blockquote> <p> return x; <em> unsigned type... </em></p> </blockquote> <p> } </p> </blockquote> <p> } </p> <p> Alternatively, boost::units should do a static assert that the type underlying the quantity is signed if that is what is intended (but why restrict it thus?) </p> <p> Found and tested the workaround on 1.47.0, but confirmed to still exist on the trunk. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/6872 Trac 1.4.3 Matthias Schabel Tue, 08 May 2012 15:47:24 GMT owner changed https://svn.boost.org/trac10/ticket/6872#comment:1 https://svn.boost.org/trac10/ticket/6872#comment:1 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Matthias Schabel</span> to <span class="trac-author">Steven Watanabe</span> </li> </ul> Ticket