vector<shared_ptr<T>>に対するfor_each

BoostML - 【bind】How do I....?


こういうことがしたいんだけど、どうすればいいの、というお話。

struct A {};
void f(const A&) {}

std::vector<boost::shared_ptr<A> > v;
std::for_each(v.begin(), v.end(), boost::bind(&f, ???));


Boost.RangeExの例が出てたのでPStade.Oven使ってやってみた。

#include <vector>
#include <boost/shared_ptr.hpp>
#include <pstade/oven/indirected.hpp>
#include <pstade/oven/algorithm.hpp>

namespace oven = pstade::oven;

struct hoge {};

struct f {
    void operator()(const hoge&) const {}
};

int main()
{
    std::vector<boost::shared_ptr<hoge> > v;

    oven::for_each(v | oven::indirected, f());
}

簡単だなー。
やっぱりRange-baseライブラリは必須だなー。


ところで、Ovenのalgorithm(for_each)に関数ポインタ渡したらエラーになったんだけど
関数オブジェクトしか渡せない?