模板元编程第六章课后习题(非答案)20151206
2015-12-05 16:25
495 查看
//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_<T1>::type::value<mpl::sizeof_<T2>::type::value),T1,T2>{}; template<class Seq> struct smallest:mpl::copy<Seq,mpl::inserter<long long,T1smallest_imp<_1,_2> >>{}; //6-0
//6-3
//toy_tree.h #pragma once #include<boost\mpl\vector.hpp> #include<boost\mpl\placeholders.hpp> 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<vec,T>{}; template<typename vec> struct inorder_view_imp<vec,nothing>{//nothing typedef vec type; }; template<typename vec,typename T0,typename T1,typename T2>//T是树 struct inorder_view_imp<vec,tree<T0,T1,T2> > { typedef typename mpl::push_back<typename inorder_view_imp<vec,T1>::type,T0>::type tmpvec; typedef typename inorder_view_imp<tmpvec,T2>::type type; }; template<class T> struct inorder_view:inorder_view_imp<mpl::vector<>,T>::type{}; //5-10 template<class T,class K> struct smaller{ typedef mpl::bool_<T::value<K::value> type; }; template<bool,class Tree,class T> struct push_back_tree; template<bool,class Tree,class T> struct push_back_type{ typedef tree<Tree,T> type; }; template<class Tree,class T> struct push_back_type<true,Tree,T>{ typedef tree<Tree,nothing,T> type; }; template<class Tree,class T> struct push_back//对一个类型push_back :push_back_type<smaller<Tree,T>::type::value,Tree,T>{}; template<class T0,class T1,class T2,class T> struct push_back<tree<T0,T1,T2>,T>//对树push_back :push_back_tree<smaller<T0,T>::type::value,tree<T0,T1,T2>,T >{}; template<class T> struct push_back<nothing ,T> { typedef T type; }; template<class T> struct push_back<tree<>,T>:tree<T>{}; 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
相关文章推荐
- 《疯狂JAVA讲义》——Singleton类
- 类和对象(代码)
- Java对象创建之new关键字和newinstance()方法
- C++
- 最近邻图像旋转代码 灰度图像 c++实现
- AES算法 Java实现
- matlab之reshape函数
- python编码检测模块chardet
- PHP面向对象1.5 继承
- C#声明数组并初始化,有三种方式
- c++ bitset
- cc2530裸机编程系列笔记1--定时器Timer1模模式的程序设计
- maven 3.3.3 + MyEclipse2015 for windows 配置
- Java内存管理机制
- C++:基于LL(1)方法的语法分析程序-1
- 文件is not found in the curren directory or on the Matlab path
- JAVA JTextField 和JTextArea的一般方法
- Python爬虫入门三之Urllib库的基本使用
- Eclipse添加C/C++头文件跳转
- Java类-Stack的学习