Boost logo

Boost :

From: Gennaro Prota (gennaro_prota_at_[hidden])
Date: 2003-01-18 12:40:41


On Fri, 17 Jan 2003 08:24:13 -0500, David Abrahams
<dave_at_[hidden]> wrote:

>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
> >
> {};
>
>Now binary<01101>::type::value = 13

Not that I think the application to "binary literals" is particularly
important, but an elegant implementation would be possible if string
literals and [] operator were allowed in constant expressions; this
way one could easily "extract" characters from a string literal and
use them as non-type template arguments of type char. Unfortunately
the committee seems on the road of prohibiting this and other similar
(and potentially more useful) uses of string literals in constant
expressions:

   http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/cwg_active.html#366

BTW, I've already felt limited by the fact that I cannot use comma
operators in constant expressions, just imagine about this one... :-/

Genny.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk