Boost logo

Boost :

From: Fredrik Blomqvist (fredrik_blomqvist_at_[hidden])
Date: 2003-05-20 18:52:38


Hi

When playing around with the mpl::bitwise functions I noticed that the
mpl::shift_right fails to take the sign of the argument type into account.
(MSV7, latest boost CVS)
I.e it does a sign extension even on unsigned types.

These two lines hopefully illustrate the problem (once again, on MSVC7)
    BOOST_STATIC_ASSERT((mpl::shift_right<mpl::size_t<~0>, mpl::size_t<1>
>::value != ~0));
    BOOST_STATIC_ASSERT((mpl::shift_right<mpl::int_<~0>, mpl::size_t<1>
>::value == ~0));
(I would also suggest that test similar to the above should be added to the
regression suite)

The problem, as I understand it, comes from the implementation of
mpl::aux::typeof, which on VC7 degenerates into a plain 'long' (ie a signed
type) regardless of input type.

The simplest local workaround I found was just to pass the original,
unmodifed, type along to mpl::shift_right_c and perform a static_cast on the
input type. (I can ofcourse send a patch if this seems like a viable
solution)

Regarding mpl::aux::typeof. Even though the full implementation isn't
available, wouldn't it be possible
to have it preserve atleast the sign of the input type on broken platforms?

regards
/ Fredrik Blomqvist


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk