3

所以想象我们有一个 mpl::vector 我们想要打印(例如 cout)它作为这样的字符串:int, string, char。如何用 boost::mpl 做这样的事情?

4

1 回答 1

3

制作一个仿函数并调用 boost::for_each:

struct print_class_name {
    template <typename T>
    void operator()( T t ) const {
       std::cout << typeid(t).name() << " ";
    }
};

boost::mpl::for_each< Sequence >(print_class_name());
于 2011-12-05T14:33:43.013 回答