しるふぃずむ

どうもプログラマです。好きなものはC#とジンギスカンです。嫌いなものはJava。プログラムおもちろいね。

fusion::transformが動かない

transform_viewは生成できますがそこから何してもエラー.
戻り値型の推論でこけてるみたいだけれど,さっぱりわかりません.
何か変な勘違いしてますかねえ…保留.

int main(int, char*[]) 
{
    struct str
    {
        template<typename T>
        auto operator()(T const& x) const
            -> std::string
        {
            return boost::lexical_cast<std::string>(x);
        }
    };
    auto vec = boost::fusion::make_vector(1, 3.14, std::string("string"));
    auto view = boost::fusion::transform(vec, str());
    auto vec2 = boost::fusion::as_vector(view); 
    // error: 'result' following the 'template' keyword does not refer to a template
    // struct result_of_nested_result : F::template result<FArgs>
    //                                              ^~~~~~

    return 0;
}

追記

@cpp_akiraさんに指摘いただきました.

  • C++03: 渡す関数オブジェクトに戻り値の情報を付加する
    • 戻り値を返すメタ関数,resultテンプレートを定義しておく(上のコードで見つからないと言っているのが多分これ)
    • 戻り値を表す型result_typeをtypedefしておく
  • C++11: マクロBOOST_RESULT_OF_USE_DECLTYPEをdefineしておく(boost::result_ofがdecltypeを用いるようになる)

で解決.後者を採用.result_ofの理解がなさ過ぎました.感謝.