|
Boost : |
Subject: Re: [boost] Proposed templated integer_sort
From: Pyry Jahkola (pyry.jahkola_at_[hidden])
Date: 2008-12-16 09:03:21
Gevorg Voskanyan wrote:
> I suggest modifying CastFloatIter() function to use memcpy for accessing floats as integers, as shown below:
Hmm, I don't think it's any better than reinterpret casting. (It actually does
the reinterpret cast when converting float const * to void const *...) I'd
suggest using a union instead, for the purpose of treating a float as integer:
template <typename To, typename From>
inline To bitwise_cast(From const & from) {
BOOST_STATIC_ASSERT(sizeof(To) == sizeof(From));
union { To to; From from; } u;
u.from = from;
return u.to;
}
Usage example: http://codepad.org/7gNXqFHO
-- Pyry Jahkola pyry.jahkola_at_[hidden]
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk