Boost logo

Boost :

From: Robert Klarer (klarer_at_[hidden])
Date: 2002-06-21 22:11:19

Paul Mensonides wrote:

> > Yes, but many compilers support a 64-bit long long type, so a
> seven_letter_word
> > template is possible. Seven letters should be enough for anyone. :-)
> Unless I'm mistaken, a multi-character literal is of type 'int', though.

Sorry, I was referring to the three_letter_word template example, which didn't use
a multibyte character.

I just realized that strings of arbitrary length can be represented portably this

#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 [];

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 };

int main() {
   nine_letter_word<'H', 'a', 'b', 'a', 'n', 'e', 'r', 'o', '.'> w;
   printf("%s\n", w.pointer);

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