From: Paul Mensonides (pmenso57_at_[hidden])
Date: 2002-06-21 14:07:41


For your amusement Boosters...

Multi-character literals give us a small, limited, and highly platform
specific way of passing string literals as arguments:

The following code works as desired on Comeau C++:

#include <iostream>

template<int D> struct X {
    inline X() {
        const int v = I;
        std::cout << reinterpret_cast<const char*>(&v) << &std::endl;
        return;
    }
};

template<> struct X<'abc'> {
    inline X() {
        std::cout << "abc" << &std::endl;
        return;
    }
};

template<> struct X<'xyz'> {
    inline X() {
        std::cout << "xyz" << &std::endl;
        return;
    }
};

int main() {
    X<'abc'>();
    X<'xyz'>();
    X<'\0cba'>(); // backwards!
    return 0;
}

Ah, a new (or old?) and fun novelty to play with!

Paul Mensonides