Rokiのチラ裏

学生による学習のログ

気になる内容メモ about C++1z #2

前のエントリから帰宅後、少しまだ時間があったので過去の気になる標準化委員会の出しているテキストを見ている。

C++ generic overload function (R1) P0051R1

関数オブジェクトをargumentsとしてぶち込んでその中でオーバーロード解決が最適なラムダを呼び出すという画期的な提案。
historyを見てみると

The paper has been split into 3 separated proposals as a follow up of the Kona meeting

  • overload selects the best overload using C++ overload resolution (this paper)
  • first_overload selects the first overload using C++ overload resolution [D0050B].
  • Providing access to the stored function objects when they are state-full [D0050C]

とあるので前回の提案と比較すると提案を三つに分割したという事かな。それぞれ、最適な関数を呼び出すoverload(このテキスト)、呼び出し可能な最初の関数を呼び出すとされるfirst_overload、格納した関数オブジェクトにアクセスする事ができる機能を持つ何らかの形のモノの3種類。

このテキスト内容がもし標準化されれば以下のような動作が可能になる。

auto visitor(std::overload(
  [](int i,int j){ ... },
  [](int i,std::string const &j){ ... },
  [](auto const &i,auto const &j){ ... }));
visitor(1,std::string{"2"} ); // (int,std::string) が呼び出される。"overload"によって。

テキストには関係ないが恐らくfirst_overloadは

auto visitor(first_overload(
    []( void * ){ ... },
    []( double ){ ... },
    []( unsigned int ){ ... } ));
visitor( 123 ) ; // doubleが呼び出される。

と書けるのかな。
また時間があるときにoverload関数ぐらいは実装を試みてみる。