zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    POJ 1611 : The Suspects (普通并查集)
    深入解析 Dubbo 3.0 服务端暴露全流程
    智能搜索推荐一体化营收增长解决方案
    云上应用系统数据存储架构演进
    EMR on ACK 全新发布,助力企业高效构建大数据平台
    介绍一下闭包和闭包常用场景?
    BFC
    高斯消元学习笔记
    云虚拟主机如何设置域名解析
    Centos7.3安装openJDK
  • 原文地址:https://www.cnblogs.com/cutepig/p/1826506.html
Copyright © 2011-2022 走看看