Subject: [Boost-bugs] [Boost C++ Libraries] #6872: units/io.hpp: autoprefix_norm_impl<> should resolve to no-op for unsigned built-in types
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2012-05-06 15:37:53
#6872: units/io.hpp: autoprefix_norm_impl<> should resolve to no-op for unsigned
built-in types
------------------------------------------------------+---------------------
Reporter: Vassilii Khachaturov <vkh@â¦> | Owner: matthiasschabel
Type: Bugs | Status: new
Milestone: To Be Determined | Component: units
Version: Boost Development Trunk | Severity: Problem
Keywords: |
------------------------------------------------------+---------------------
The code
using namespace boost::units;
const quantity<si::length, int> boa = 5 * si::meters;
std::cout << boa << std::endl;
prints "5 m", as expected, yet
using namespace boost::units;
const quantity<si::length, unsigned int> boa = 5 * si::meters;
std::cout << boa << std::endl;
fails to compile due to the std::abs call being ambiguous in io.hpp:
template<class T>
struct autoprefix_norm_impl<T, true>
{
typedef double type;
static double call(const T& arg) { return std::abs(arg); }
};
There should be a specialization resolving to a no-op (just return the
arg) for unsigned types.
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:
namespace std {
template<typename Unsigned>
typename boost::enable_if<boost::is_unsigned<Unsigned>,
Unsigned>::type
abs(const Unsigned& x)
{
return x; // unsigned type...
}
}
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?)
Found and tested the workaround on 1.47.0, but confirmed to still exist on
the trunk.
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/6872> 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:09 UTC