On 28 March 2018 at 21:23, Andrey Semashev via Boost
On 03/28/18 22:10, Stefan Seefeld via Boost wrote:
On 28.03.2018 14:48, Christian Henning via Boost wrote:
I would suggest casting to unsigned first and then performing the math.
I assume this is what you meant:
template <> struct channel_convert_to_unsigned<bits32s> : public std::unary_function
{ typedef bits32 type; type operator()(bits32s x) const { uint32_t a = static_cast (x); a += (1 << 31); return static_cast<bits32>(a); } };
Or simply replace `static_cast<bits32>(x+(1<<31))` by `static_cast<bits32>(x)+(1<<31)` (i.e., cast `x` rather than the full expression).
Rather:
static_cast<bits32>(x)+(static_cast<bits32>(1)<<31)
to make it compatible with older C++ versions.
I think Andrey's version also sticks out and documents the danger better, than 'cosmetic' shuffle of one bracket. Best regards, -- Mateusz Loskot, http://mateusz.loskot.net