Advertisement
Guest User

Untitled

a guest
Jun 25th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. //
  2. // Created by nidal on 6/24/2018.
  3. //
  4.  
  5. #ifndef OOP5_LIST_H
  6. #define OOP5_LIST_H
  7.  
  8. template<typename...>
  9. struct List{};
  10.  
  11.  
  12. /*********************************************/
  13. /* List */
  14. /*********************************************/
  15.  
  16. template <typename...>
  17. struct List;
  18.  
  19.  
  20. template<typename H, typename... T>
  21. struct List<H,T...> {
  22. public:
  23. typedef H head ;
  24. typedef List<T...> next ;
  25. constexpr static int size = 1 + sizeof...(T);
  26. };
  27.  
  28. template<>
  29. struct List<> {
  30. public:
  31. constexpr static int size = 0;
  32. };
  33.  
  34.  
  35. template <typename T>
  36. struct List<T>
  37. {
  38. typedef T head;
  39. typedef List<> next;
  40. constexpr static int size = 1;
  41. };
  42.  
  43.  
  44. /*********************************************/
  45. /* PrependList */
  46. /*********************************************/
  47.  
  48. template <typename...>
  49. struct PrependList;
  50.  
  51.  
  52. template<typename H, typename... T>
  53. struct PrependList<H, List<T...>> {
  54. public:
  55. typedef List<H,T...> list ;
  56. };
  57.  
  58.  
  59.  
  60.  
  61.  
  62. /*********************************************/
  63. /* ListGet */
  64. /*********************************************/
  65.  
  66.  
  67.  
  68. template <int N ,typename... T>
  69. struct ListGet;
  70.  
  71. template<int N, typename H,typename... T >
  72. struct ListGet<N, List< H,T... > >
  73. {
  74. public:
  75. typedef typename ListGet<N-1, List<T... >>::value value;
  76.  
  77. };
  78.  
  79. template<typename H, typename... T>
  80. struct ListGet<0,List<H,T... >>{
  81. typedef H value;
  82. };
  83. /*********************************************/
  84. /* setLIst */
  85. /*********************************************/
  86.  
  87.  
  88. template <int N ,typename... T>
  89. struct ListSet;
  90.  
  91. template<typename H, typename... T>
  92. struct ListSet<0, List<H,T... >>{
  93. typedef List<H,T... > list;
  94. };
  95.  
  96. template<int N,typename H, typename... T>
  97. struct ListSet <N, H, List<T...>> {
  98. public:
  99. typedef typename PrependList< H, typename ListSet<N-1, H,List<T...>> ::list>::list list ;
  100. };
  101.  
  102.  
  103. /*********************************************/
  104. /* INT<value> */
  105. /*********************************************/
  106.  
  107. template<int N>
  108. struct Int{
  109. public:
  110. constexpr static int value = N;
  111.  
  112. };
  113.  
  114.  
  115. #endif //OOP5_LIST_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement