Boost logo

Boost :

From: Daryle Walker (darylew_at_[hidden])
Date: 2005-09-10 18:22:57

On 9/9/05 1:24 PM, "Eric Niebler" <eric_at_[hidden]> wrote:

> Well, you haven't defined a primary template, so add_unsigned<unsigned>
> will not compile. IMO, your primary template should "typedef T type;".
> But depending on what you're trying to do, this may work, and it's a lot
> shorter:
> template< typename Int >
> struct add_unsigned {
> typedef typename boost::uint_t<
> sizeof(Int) * CHAR_BIT
> > ::least type;
> };

Your formula will include any unused junk bits a type may have. You can use
"std::numeric_limits<Int>::digits" for the number of bits used. Note that
the "uint_t" template itself uses that "numeric_limits" expression for its
internals, so you better use it to avoid a mismatch.

Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT hotmail DOT com

Boost list run by bdawes at, gregod at, cpdaniel at, john at