C++テンプレートメタプログラミングでの文字列の扱い方で行き詰まった

C++テンプレートメタプログラミングでいろいろ試していたら行き詰まった.

文字列の先頭の要素(や特定の位置の要素)をコンパイル時に取得できるようにしたい.以下のようにテンプレート引数に文字列を入れるような形で書きたいのだが,どうやらこれは無理らしい.

#include <iostream>
using namespace std;

(省略)

int main(int argc, const char *argv[]) {
  const char c = front<"Hello, world!">::value;
  cout << c << endl; // "H"と出力してほしい
  return 0;
}

そこで,いろいろ書き直したところ以下のような感じになったが,やはりうまく行かない.コンパイル時に"an array reference cannot appear in a constant-expression"と怒られる.

#include <iostream>
using namespace std;

struct hello {
  static const char value[];
};
const char hello::value[] = "Hello, world!";

template <class T>
struct front {
  static const char value = T::value[0]; // コンパイルエラー
};

int main(int argc, const char *argv[]) {
  const char c = front<hello>::value;
  cout << c << endl; // "H"と出力してほしい
  return 0;
}

Boost.MPLのstringを使ってしまえばいろいろ楽なんだろうけど,せっかく勉強しているのだから自前で実装してみたいし,何よりBoost.MPLのstringは以下のように初期化が気持ち悪いのであまり好きじゃない.

// 一文字ずつテンプレート引数に渡す場合
typedef mpl::string<'H','e','l','l','o',',',' ','w','o','r','l','d','!'> hello;

// n文字ずつ'...'に入れる場合(n <= 4まで可)
typedef mpl::string<'Hell','o, w','orld', '!'> hello;

どうにかならないものかな.ポインタ型の値をテンプレート引数に取ったり,*や[]による参照結果をstatic constなメンバ変数に入れられるといいんだけど….


<追記 2010/09/09 06:12>
やっぱりBoost.MPLのstringを使う以外に手はなさそうだ….