Boost.Phoenix V3 - 関数のbind化

Boost.Phoenix V3では、boost::phoenix::functionに関数オブジェクトをアダプトすることで、boost::bindのような部分評価の能力を得ることができるようになります。

#include <iostream>
#include <boost/phoenix.hpp>

struct add_ {
    template <class>
    struct result {
        typedef int type;
    };

    int operator()(int a, int b) const
    {
        return a + b;
    }
};

boost::phoenix::function<add_> add;

using boost::phoenix::arg_names::_1;

int main()
{
    std::cout << add(_1, 2)(3) << std::endl;
}
5

ただ現状、boost::phoenix::functionが直接resultテンプレートを要求するので、boost::result_ofに対応していません。
それもあって、C++0xのdecltypeで簡単に定義することもできません。


追記:
使い方が若干異なるようですが、V2でもできるようです。

#include <iostream>
#include <boost/ref.hpp>
#include <boost/spirit/include/phoenix.hpp>

struct add_ {
    template <class A0, class A1>
    struct result {
        typedef int type;
    };

    int operator()(int a, int b) const
    {
        return a + b;
    }
};

boost::phoenix::function<add_> const add;

using boost::phoenix::arg_names::_1;

int main()
{
    std::cout << add(_1, boost::cref(2))(boost::cref(3)) << std::endl;
}