的boost :: MPL向量和的for_each:如何打印avector作为一个元组? [英] Boost::MPL Vector and For_Each: how to print avector as a tuple?

查看:143
本文介绍了的boost :: MPL向量和的for_each:如何打印avector作为一个元组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,想象一下,我们有我们想要打印(例如COUT)它是这样一个字符串MPL ::向量:整型,字符串,字符。如何做这样的事情与升压:: MPL?

So imagine we had a mpl::vector we want to print (cout for example) it as such string: int, string, char. How to do such thing with boost::mpl?

推荐答案

请函子,并调用的boost :: for_each的:

Make a functor and call 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());

这篇关于的boost :: MPL向量和的for_each:如何打印avector作为一个元组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆