daily pastebin goal
57%
SHARE
TWEET

Untitled

a guest Apr 17th, 2018 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <typeinfo>
  3.  
  4. class NullType {};
  5.  
  6. template<typename T=NullType, typename ... U>
  7. struct TypeList {
  8.     using head = T;
  9.     using tail = TypeList<U ...>;
  10. };
  11.  
  12. template<typename T>
  13. struct TypeList<T> {
  14.     using head = T;
  15.     using tail = NullType;
  16. };
  17.  
  18. using CharList = TypeList<char, signed char, unsigned char>;
  19. using EmptyList = TypeList<>;
  20.  
  21. // struct TypeAt<unsigned int i, class T>;
  22.  
  23. template<unsigned int i, typename T, typename ... U>
  24. struct TypeAt<0, TypeList<T, U...>> {
  25.     using Result = T;
  26. };
  27.  
  28. template<unsigned int i, class T, class ... U>
  29. struct TypeAt<i, TypeList<T, U ...>> {
  30.     using Result = typename TypeAt<i - 1, U...>::Result;
  31. };
  32.  
  33. // template <typename Head, typename Tail>
  34. // struct Length<TypeList<Head, Tail>> {
  35. //     enum { value = Length<Tail>::value + 1};
  36. // };
  37.  
  38. // template <typename Head, typename Tail>
  39. // struct Length<TypeList<NullType, NullType>> {
  40. //     enum { value = 0};
  41. // };
  42.  
  43. int main() {
  44.  
  45.     std::cout << typeid(EmptyList::head).name() << std::endl;
  46.     std::cout << typeid(EmptyList::tail).name() << std::endl;
  47.     // std::cout << Length<EmptyList>::value << std::endl;
  48.     std::cout << typeid(TypeAt<0, CharList>::Result).name() << std::endl;
  49.    
  50. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top