回答があるのに、質問が無い?

イントロ無しでいきなり曲が始まるというパターンかというと、そうでもない。11/20 に、「C++の次期仕様「C++0x」のポイント 〜Bjarne Stroustrup氏との対話〜 第5回 C++国際標準化委員会による初心者への配慮」という記事が公開された。

「はじめに」という章の後、「Question 5: 次期C++仕様のポイントと策定経緯」と続くのであるが、質問文は見当らない*1。その後いきなり「回答」と言う章が続く。最後の「対話のポイント」という章も、Stroustrup氏のメールと関係ある内容とは思えない。記事にして、何を読者に言及しようとしているのだろうか。

日本語記述や、記事のレイアウトにもどうかと思える部分が多い*2。一箇所だけ例を挙げる。

「実際、同氏の公開文書に目を通してみると、標準化委員会の席で強い希望を表明したが受け入れられなかった、などといった記述がところどころに散見されます。「C++0x」と呼ばれる次期仕様はどのように策定されるのでしょうか。お尋ねしました。」

「ところどころに見られる」というのが、「散見」という言葉の意味だと、私は解釈していた*3。元記事のような使い方をしていると、「単に"散見"って書きたかっただけちゃうんか!」などと文句を言われるだろうなあと思ってしまう。

以下、元記事から Stroustrup 氏からのメール部分を引用しながら、日本文を続けるスタイルで書いた。読み易さを考慮して文を分割した部分はあるが、極力逐語訳に近い文書にしたつもりだ。だからタイトルがない。Strustrup氏からの元メールのパラグラフ毎に日本語の段落を割り当てるように構成した*4

C++言語用語の日本語訳について調べた。C++0x の言語仕様には、まだ正式な日本語版が見当らなかった。「Faith and Brave - C++で遊ぼう」、「ntnekの日記」を始め、web上に公開しておられる情報を参考にさせていただきました。ありがとうございます*5

対訳

There are a lot of compiler, tools, and language experts on the committee. Those and library builders dominate, and that's a pity. Ideally, we'd have a majority of experienced developers to help guide the work. However, the committee is not alone in its fault here. Essentially every one of those 100 proposals and maybe 200 more distinct "mere suggestions" came from people outside the committee. A member of the committee rarely just comes up with a proposal on his own. The community is the source of much of the pressure to add language features; just watch any web discussion on how to improve the language and you'll find a chorus of demands for new features together with some (often loud and unconstructive) complaints that the language is too large already.

コンパイラの、ツールの、そして言語のエキスパートが委員会には沢山居る。彼等とライブラリ開発者が支配している*6、これは残念なことである。理想を言えば、経験を積んだ開発者に、この仕事を先導してもらえたら良かったのだ。とは言え、ここでの誤ちは委員会だけのせいではない。重要なことに、あなた(元記事の著者のこと)が書いていた 100 の提案*7に加え、多分 200 程の独特な「採るに足りない提案」は、それぞれが委員会の外部から出てきたものだ。委員会のメンバは滅多に、自分に関わることの提案は出さない。委員会は、言語に機能を追加せよという圧力の源の大元である。C++言語を改良する方法に関する web での討論をどれでもかまわないので見てみれば、新機能に対する要求が、C++ は既に大き過ぎるという (たいていは煩くかつ非建設的な) 不満と一緒にハーモニーを奏でているかと思う。

Fortunately, most of the about 50 proposals that were accepted are so minor that most users will say something like "Huh? We couldn't do that before?" Examples are creating an alias for a template with a template argument bound and using a local type as a template argument:

// define Vec<T> to be an alias for vector<T,My_allocator<V>>:
using template<class T> Vec = std::vector<T,My_allocator<T>>;

void f()
{
    enum Color { blue, green, red };
    std::vector<Color> vc; // not allowed in C++98
    // …
}

幸いなことに、受け付けた約 50 の提案は、重要性が低く、大部分のユーザが「エッ?もっと前に出来なかったのか?」くらいの事しか言わないであろう程度のものである。例えば、テンプレート引数を束縛したテンプレートにエイリアスを生成すること、およびテンプレート引数としてローカル型を使うこと、である。

// vector<T,My_allocator<V>> に、Vec<T> というエイリアスを定義する:
using template<class T> Vec = std::vector<T,My_allocator<T>>;
    void f()
    {
        enum Color { blue, green, red };
        std::vector<Color> vc; // C++98 では禁じ手
        // …
    }

The alias mechanism was frequently requested under the name "template typedef." Did you know you couldn't do that? Did you know that the definition of vc in f() was not allowed and why? Well, both work in C++0x, and you don't even have to add a space between the two >s in vector>.

エイリアス手法 (alias mechanism) は、「テンプレートの型定義 (template typedef)」と呼ばれ、頻繁に要望されていた。そんな事は出来ないのを知ってましたか? "f()" の中で "vc" を定義できないのを知ってましたか?まあ、C++0x でならどちらも使える、それに "vector>." のふたつの ">" の間に空白を入れる必要さえない。

So, one thing that C++0x does for novices is saving them from unnecessary restrictions in a number of places. To do so was a stated aim: "To make the language rules more general and uniform." That's one of the two ways of making a language easier to use for novices. The other is "provide features that directly support doing simple things simply." Most of those would be new libraries, and there are preciously few of those.

なので、様々な局面で、初心者が不要な制限にひっかかないようにすることが、C++0x が初心者向けにできることのひとつである。それを実現するために、言明した目標が、「言語の規則はより一般的かつより統一されたものにすること。」である。これは初心者にとって、ある言語をより使い易くするための、ふたつの方法のうちひとつである。もうひとつは、「単純な事を単純にできることを、直接サポートする機能を提供する」ことである。ほとんどは新規ライブラリにすべきだったが、まったく何のライブラリもできていない。

I would have liked to see many more libraries, but we did get a few: regular expressions, hashed containers (e.g. unordered_map), smart pointers, tuples, threads, time duration, an asynchronous return mechanism (future). Some of these will help novices as well as experts. None of these are new - you could have used them (or close equivalents) for years, but they now become standard and shipped with every implementation. That especially helps novices, who are often unwilling to download and install a key component (e.g. libraries from boost.org), and people in companies with policies against the use of non-standard libraries they didn't write in-house.

もっと多くのライブラリを期待していたが、手に入れたのは少しだけである。即ち、正規表現、ハッシュ系コンテナ (unordered_map のことだ)、スマートポインタ、タプル、スレッド、時刻と期間のサポート(time duration)、非同期 return (先の話だが) である。幾つかは初心者にも熟練者同様に、役立つものとなる。ひとつとして新規なものは無い -- 何年も使っているかもしれない (もしくは見分けが付かない程の同等物)、しかし今や標準となり、全ての実装の一部となったのである。これは特に、ほとんどの者が主要なコンポーネント (例としては、boost.org 提供のライブラリ) をダウンロードしインストールすることを好まない初心者、また自社製以外の非標準ライブラリの利用に反対する方針を持つ企業に居る人々には役に立つことである。

Much of the help for novices comes from new features that makes the standard library easier to use and faster. My favorite is the initializer lists:

vector<string> names = { "Aho", "Weinberger", "Kernighan" };
map<const char*,string> designers = {{"C", "Ritchie"}, { "C++", "Stroustrup" }, { "BCPL", "Richards"}
  };

初心者向けに役に立つことの大部分は、標準ライブラリをより簡単にかつより迅速に使えるようにする新機能のお陰で可能となっている。私のお気に入りは、初期化子リスト(Initializer List)だ。

vector<string> names = { "Aho", "Weinberger", "Kernighan" };
map<const char*,string> designers = {{"C", "Ritchie"}, { "C++", "Stroustrup" }, { "BCPL", "Richards"}
  };

None of the C++98 alternatives are as simple and direct.

C++98 での代替方法はどれも、こんなに単純でも直感的でもない。

追記

ご指摘をいただき、文章を一部変更いたしました。原因は私の読み違いでした。「対訳」の第1節と脚注 (こちらは便乗で) を修正いたしました。

  • 第1節
    • 修正前: とは言え、現在の誤ちは委員会だけのせいではない。あなた(元記事の著者のこと)が書いていた 100 の提案と、多分 200 程のそれぞれ独特な「採るに足りない提案」が、委員会の外部から出てきた。
    • 修正後: とは言え、ここでの誤ちは委員会だけのせいではない。重要なことに、あなた(元記事の著者のこと)が書いていた 100 の提案に加え、多分 200 程の独特な「採るに足りない提案」は、それぞれが委員会の外部から出てきたものだ。
  • 脚注
    • 修正前: 質問と称している英文の中で、「100の提言中で約 90は」と書いたからだ。私は、記事の著者が「十中八九」の意図で書いたのではないかと疑っている。
    • 修正後: (質問と称している英文の中で、「100の提言中で約 90は」と書いているのを受けた記述と解釈した。記事の著者が「十中八九」の意図で書いたのではないかという疑問が残る。

*1:この質問と称する部分、英語にも日本語にも問題が多い。別途ツッコム予定。

*2:これまた別途対応予定

*3:「あちらこにらにちらほらと見えること」と広辞苑には載っていた。

*4:元記事はこのあたり、無茶苦茶である。

*5:現状では、変に日本語用語を使うより、原語のままのほうが通りが良いかと判断した。適宜使いわけたつもりではある

*6:「ライブラリ開発者が」というのが元記事には無い。省いた理由は不明。

*7:質問と称している英文の中で、「100の提言中で約 90は」と書いているのを受けた記述と解釈した。記事の著者が「十中八九」の意図で書いたのではないかという疑問が残る。