test boost::fusion

// testBoost.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#if 1

#include <boost/fusion/sequence.hpp>
#include <boost/fusion/include/sequence.hpp>
#include <boost/fusion/include/vector.hpp>
#include <string>
#include <iostream>
#include <boost/fusion/algorithm.hpp>
#include <boost/fusion/include/algorithm.hpp>
#include <boost/fusion/support/is_sequence.hpp>
#include <boost/fusion/include/is_sequence.hpp>

 

template <bool IsSeq> struct print_xml;

template <>
struct print_xml<false>
{
    template <typename T>
    void operator()(T const& x) const
    {
        std::cout
            << '<' << typeid(x).name() << '>'
            << x
            << "</" << typeid(x).name() << ">\n"
            ;
    }
};

template <>
struct print_xml<true>
{
    template <typename T>
    void operator()(T const& x) const
    {
  boost::fusion::for_each(x, value_printer());
    }
};

struct value_printer
{
    template< typename T > void operator()(T const& x) const
    {
        print_xml<boost::fusion::traits::is_sequence<T>::value > printXml;
  printXml(x);
    }
};

int _tmain(int argc, _TCHAR* argv[])
{
 typedef boost::fusion::vector<int, char, std::string> Stuff;
 Stuff stuff(1, 'x', "howdy");
 boost::fusion::vector<int, char, Stuff> stuff2(2, 'y', stuff);

 int i = boost::fusion::at_c<0>(stuff);
 char ch = boost::fusion::at_c<1>(stuff);
 std::string s = boost::fusion::at_c<2>(stuff);

 //boost::fusion::for_each(stuff, print_xml());
 value_printer()(stuff2);

 return 0;
}

#endif

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值