Boost logo

Boost Users :

From: David Abrahams (dave_at_[hidden])
Date: 2006-11-13 10:47:50


"Michael Marcin" <mmarcin_at_[hidden]> writes:

> Thank you. It works and makes sense now because of your explanations.
> I've been working for a year now using C++ almost exclusively and there is
> still so much left to learn *sigh*.

You're welcome. James Dennett reminded me off-list that there's a
trick for doing power-of-2 detection: (n>0 and (n&(n-1))==0)

// something like this
template <class N>
struct is_power_of_2
  : mpl::and<
        mpl::greater<N,mpl::int_<0> >
      , mpl::equal_to<
             typename mpl::bitand<
                  N
                , typename mpl::prior<N>::type
>::type
           , mpl::int<0>
>
>
{};

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.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