|
Boost : |
From: Fredrik Blomqvist (fredrik_blomqvist_at_[hidden])
Date: 2003-01-17 08:55:03
"David Abrahams" <dave_at_[hidden]> wrote in message
news:uptqvnc3m.fsf_at_boost-consulting.com...
> "Fredrik Blomqvist" <fredrik_blomqvist_at_[hidden]> writes:
>
> > Hi there,
> >
> > I thought I'd forward this little link:
> >
http://www.flipcode.com/cgi-bin/msg.cgi?showThread=Tip-CPPCompileTimeBinCons
> > t&forum=totd&id=-1
> > (several improved versions of the initial code appear in the thread)
> >
> > This has most likely been done before but IMO a boostified version using
MPL
> > and PP could
> > actually be a useful convenience utility.
>
>
> Aleksey and I were just discussing this one. As soon as he's done
> implementing the "for_" algorithm it could look like this:
>
> template <unsigned long N> // N must be an *octal* constant
> struct binary
> : for_<N, _1, shift_right<_1, int_<3> >, // "forward" state,
condition, step
> plus<bitand_<_1, int_<1> >, _2> // "backward" step
> >
> {};
>
cool!
The octal "feature" was also discussed in the link above and a good idea was
to use the PP to _always_ insert a leading zero, eliminating a potentially
very annoying bug..
Secondly, another idea that was presented by Jarkko L. was simply to create
a "mega-enum" something like this:
enum {
b0, b1,
};
enum {
b00, b01, b10, b11,
};
enum {
b000, b001, b010, ....
}
etcetera...
as I said, quite a few variantions came up in the previous thread, many
along this second version.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk