posts - 58,  comments - 75,  trackbacks - 0

        Modern C++ Design中实现了一个自动生成类的方法。它用的是Loki中的TypeList。我在这里使用了boost MPL中的vector来作为类型的容器。按boost MPL库的设计理念,其他的类型容器也应该可以利用这里的实现的(没有试过,可能有问题,特别是map类型容器)

        实现如下(注:我已将boost的头文件放到了vc的include目录中)
  
    #include < boost/mpl/vector.hpp >
    #include < boost/mpl/front.hpp >
    #include < boost/mpl/pop_front.hpp >

    template< typename Type >
    struct Holder
    {
        Type value_;
    };

    template< typename TypeSequeue, template< typename > class Unit >
    struct TypeConstract : public Unit< typename boost::mpl::front< TypeSequeue >::type >,
                           public TypeConstract< typename boost::mpl::pop_front< TypeSequeue >::type,
                                                 Unit >
    {
    };

    template< template< typename > class Unit >
    struct TypeConstract< boost::mpl::vector<>::type, Unit >
    {
    };                                                                                                                                                                      

posted on 2007-04-07 16:02 walkspeed 阅读(1719) 评论(1)  编辑 收藏 引用 所属分类: STL、Boost、范型编程C++语言

FeedBack:
# re: 用vector来自动生成类
2009-05-09 17:59 | yshuise
你测试类没有?
我写了一个,你看看:
http://blog.csdn.net/yshuise/archive/2009/05/09/4163518.aspx  回复  更多评论
  

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理



<2007年4月>
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345

常用链接

留言簿(4)

随笔分类(64)

随笔档案(58)

文章分类(3)

文章档案(3)

相册

收藏夹(9)

C++零碎

好友

搜索

  •  

积分与排名

  • 积分 - 157880
  • 排名 - 163

最新评论

阅读排行榜

评论排行榜