Boost logo

Boost :

From: David Abrahams (david.abrahams_at_[hidden])
Date: 2002-06-21 23:20:08


From: "Robert Klarer" <klarer_at_[hidden]>

> I just realized that strings of arbitrary length can be represented
portably this
> way:
>
> #include <stdio.h>
>
> typedef unsigned long letter;
>
> template <letter l1 = 0,
> letter l2 = 0,
> letter l3 = 0,
> letter l4 = 0,
> letter l5 = 0,
> letter l6 = 0,
> letter l7 = 0,
> letter l8 = 0,
> letter l9 = 0>
> struct nine_letter_word {
> static const char pointer [];
> };

No way! What type is that? You're allowed to have dimensionless array
types?!? I thought that was just another way of writing const char*. You're
a sick man!

> template <letter l1,
> letter l2,
> letter l3,
> letter l4,
> letter l5,
> letter l6,
> letter l7,
> letter l8,
> letter l9>
> const char nine_letter_word<l1, l2, l3, l4, l5, l6, l7, l8,
l9>::pointer[]
> = { l1, l2, l3, l4, l5, l6, l7, l8, l9, 0 };

Umm, OK, the type is determined by the initialization... wierd but
understandable.
And this works for 4 letter words, too. Sick ;-P

-Dave


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