模板元编程第六章课后习题(非答案)20151206

//6-0
template<bool,class T1,class T2>
struct T1smallest{
    typedef T1 type;
};
template<class T1,class T2>
struct T1smallest<false,T1,T2>{
    typedef T2 type;
};

template<class T1,class T2>
struct T1smallest_imp:T1smallest<(mpl::sizeof_::type::value::type::value),T1,T2>{};

template<class Seq>
struct smallest:mpl::copylong long,T1smallest_imp<_1,_2> >>{};
//6-0

//6-3

//toy_tree.h
#pragma once
#include
#include
using namespace boost;
using namespace mpl::placeholders;
//5-10
struct nothing{};
template<typename T0=nothing,typename T1=nothing,typename T2=nothing>
struct tree
{
    typedef tree type;
    typedef T0 root;
    typedef T1 lson;
    typedef T2 rson;
};

template<typename vec,typename T>//T是个普通类型
struct inorder_view_imp:mpl::push_back{};
template<typename vec>
struct inorder_view_imp{//nothing
    typedef vec type;
};

template<typename vec,typename T0,typename T1,typename T2>//T是树
struct inorder_view_imp >
{

    typedef typename mpl::push_back<typename inorder_view_imp::type,T0>::type tmpvec;
    typedef typename inorder_view_imp::type type;
};



template<class T>
struct inorder_view:inorder_view_impvector<>,T>::type{};

//5-10
template<class T,class K>
struct smaller{
    typedef mpl::bool_ type;
};

template<bool,class Tree,class T>
struct push_back_tree;
template<bool,class Tree,class T>
struct push_back_type{
    typedef tree type;
};
template<class Tree,class T>
struct push_back_type<true,Tree,T>{
    typedef tree type;
};



template<class Tree,class T>
struct push_back//对一个类型push_back
    :push_back_type::type::value,Tree,T>{};

template<class T0,class T1,class T2,class T>
struct push_back,T>//对树push_back
    :push_back_tree::type::value,tree,T >{};

template<class T>
struct push_back
{
    typedef T type;
};
template<class T>
struct push_back,T>:tree{};


template<class Tree,class T>
struct push_back_tree<false,Tree,T>{
    typedef tree<typename Tree::root,typename push_back<typename Tree::lson,T>::type,typename Tree::rson> type;
};
template<class Tree,class T>
struct push_back_tree<true,Tree,T>{
    typedef tree<typename Tree::root,typename Tree::lson,typename push_back<typename Tree::rson,T>::type> type;
};

template<class tree>
struct binary_tree_inserter
{
    typedef tree state;
    typedef push_back<_,_> operation;
};

//6-3

你可能感兴趣的:(模板元编程)