Boost logo

Boost :

From: Robert Klarer (klarer_at_[hidden])
Date: 2002-06-21 18:25:06


I, for one, am highly entertained! Your idea helped me to think
of this. Is this a new idea? It works (i.e. it prints "C++")
when compiled with the IBM compiler. I guess that the next step
is a make_three_letter_word function.

#include <stdio.h>

const int char_bit = 8;

typedef unsigned long letter;
typedef unsigned long word;

template <letter l1,
          letter l2,
          letter l3>
struct three_letter_word {

   static const word value = (l1 << (3 * char_bit)) +
                             (l2 << (2 * char_bit)) +
                             (l3 << (1 * char_bit)) +
                             0; /* NULL terminator */
   static const char * pointer;
};

template <letter l1,
          letter l2,
          letter l3>
const word three_letter_word<l1, l2, l3>::value;

template <letter l1,
          letter l2,
          letter l3>
const char * three_letter_word<l1, l2, l3>::pointer
   = reinterpret_cast<const char *>(&three_letter_word<l1, l2, l3>::value);

int main() {
   three_letter_word<'C', '+', '+'> w;
   printf("%s\n", w.pointer);
}


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