boost::fusion::vector のすべての要素に対して関数を呼び出したいと思います。要素は次のようなタイプです。
class A {
...
void print_with_prefix(const char *prefix) {
std::cout << prefix << *this;
}
};
この関数は、次の方法で各要素に対して呼び出すことができます。
// Call print_with_prefix() on a boost::fusion sequence:
struct CallPrintWithPrefix {
const char *prefix_;
CallPrintWithPrefix(const char *prefix) : prefix_(prefix) {}
template <class T> void operator()(T &element) const {
element.print_with_prefix(prefix);
}
}
template <class BoostFusionVector>
void print_all(BoostFusionVector &v, const char *prefix) {
boost::fusion::for_each(v, CallPrintWithPrefix(prefix));
}
ただし、print_all()
ヘルパー クラスを含めるこの実装はかなり見苦しく、複雑すぎるようです。C++0x が許可されていると仮定すると、それを実装する正しい方法は何ですか?