コンストラクタの部分評価

Boost 1.43.0から入ったFunctional/Factoryは、ユーザーコードではどういったときに使うのかと思っていたら、bindと組み合わせてコンストラクタの部分評価に使えそうです。
こんな感じ。

#include <boost/functional/value_factory.hpp>
#include <boost/bind.hpp>
#include <boost/function.hpp>
#include <boost/assert.hpp>

struct Point {
    int x, y;
    Point(int x_, int y_) : x(x_), y(y_) {}
};

int main()
{
    boost::function<Point(int)> f = boost::bind(boost::value_factory<Point>(), 3, _1);
    const Point p = f(2); // yをあとから渡す

    BOOST_ASSERT(p.x == 3);
    BOOST_ASSERT(p.y == 2);
}

これは使いやすいかもしれない。


追記:
コンストラクタの部分評価は、setter排除のために使えます。