July 2007 ISO C++ Standards Meeting

Herb SutterのTrip Report: July 2007 ISO C++ Standards Meetingの抄訳:

ISO C++標準委員会が7月15〜20日トロントで開催された。

C++0xドラフトに採択された機能:

enum class(N2347)
C++/CLIから輸入された拡張。enumのベースになる型を明示できるようになり、専用のスコープを持つことができ、int(だかなんだか)への暗黙の変換がなくなる。
Saving exceptions (N2179)
例外を保管して後で投げられるようにする言語拡張。とりわけ並列処理で、あるスレッドで拾った例外をよそのスレッドに回せる。
constexpr (N2235 and N2349)
一般化された定数式。日本語で言うと…コンパイル時定数らしく振舞うコンパイル時定数を書けるってこと。次の例を考える:
    constexpr int square(int x) { return x * x; }

square()をコンパイル時定数を引数にして呼び出すと、square()の結果もコンパイル時定数になる。だから例えば

    float arr[ square(9) ]; // ok, array of length 81

と書ける。

decltype (N2343 and N2194; for discussion see N2115 and N1978)
式の型を取得して、型に対してするようなこと(その型の変数を宣言したりとか)ができるようになる。実行時コストなしのリフレクション。例えばイテレータの参照する型を知りたいなら、今ならイテレータvalue_typeを調べる:
    template
    void f( Iter it ) {
      Iter::value_type v = *it;
      ...
    }

んでdecltypeがあると:

    template
    void f( Iter it ) {
      decltype(*it) v = *it;
      ...
    }

この機能がC++0xの標準ライブラリでどう使われているか興味があるならN2194, "decltype for the C++0x Standard Library"をどーぞ。

alignof (N2341)
システムごとにがんばってどうこうしなくても、アライメントの整合した記憶域を確保したり、型のアライメントに関する要求を調べたりできるようになる。
=default and =delete (N2346 and N2292)
4つの特殊なデフォルト関数(デフォルトコンストラクタ、コピーコンストラクタ、コピー代入演算、デストラクタ)を制御したいなら、これがご期待に沿います。

その他の機能:

  • N2340 "C99 Compatibility : _ _ func _ _ and predeclared identifiers (revision 2)"
  • N2342 "POD's Revisited; Resolving Core Issue 568 (Revision 5)"
  • N2293 "Standard Library Applications for Explicit Conversion Operators"
  • N2348 "Wording for std::numeric_limits::lowest()"
  • N2350 "Container insert/erase and iterator constness (Revision 1)"
  • N2351 "Improving shared_ptr for C++0x, Revision 2"
  • N2299 "Concatenating tuples" (except change the name of the four functions named concatenate to tuple_cat)
  • N2007 "PROPOSED LIBRARY ADDITIONS FOR CODE CONVERSION" (hey, don't blame me for screaming, that's the title...)
  • N2308 "Adding allocator support to std::function for C++0x" (except change the pass-by-value Allocator argument to pass-by-const-reference)
  • N2321 "Enhancing the time_get facet for POSIX® compatibility, Revision 2"
  • N2353 "A Specification for vector" into the C++0X Working Paper. (After all, no meeting would be complete without some discussion of vector...)

次回の会合は10月にハワイのコナ。その次は来年2月にワシントン。さらに先は6月にフランスのソフィアアンティポリス。お近くにいらっしゃるならお気軽にご参加ください。