Boost logo

Boost Users :

From: David Abrahams (dave_at_[hidden])
Date: 2008-08-16 16:54:24


on Sat Aug 16 2008, Zeljko Vrba <zvrba-AT-ifi.uio.no> wrote:

> I get a warnings about type truncation, and obviously, I don't like them. But
> I like explicit casts and turning off warnings even less. No, I don't want to
> tie together size_type and task id type (unsigned int). One reason is
> "aesthetic", another reason is that I don't want the task id type to be larger
> than necessary (heck, even a 16-bit type would have been enough), because the
> task IDs will be copied verbatim into another std::vector<unsigned> for further
> processing (edge lists of a graph). Doubling the size of an integer type shall
> have bad effects on CPU caches, and I don't want to do it.
>
> What to do? Encapsulate into "get_next_id()" function? Have a custom size()
> function/macro that just casts the result of vector::size and returns it?

Have you looked at boost::numeric_cast?

-- 
Dave Abrahams
BoostPro Computing
http://www.boostpro.com

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net