fork download
  1. #include <iostream>
  2. #include <typeinfo>
  3.  
  4. template
  5. <
  6. template <typename...> class BeCurry,
  7. typename... Params
  8. >
  9. struct Curry
  10. {
  11. using type = BeCurry<Params...>;
  12. };
  13.  
  14. template
  15. <
  16. template <typename...> class BeCurry
  17. >
  18. struct Curry<BeCurry>
  19. {
  20. using type = BeCurry<>;
  21. };
  22.  
  23. template
  24. <
  25. template <typename...> class BeCurry,
  26. typename... Params
  27. >
  28. struct Currying
  29. {
  30. template <typename... OtherParams>
  31. using curried = typename Curry<BeCurry, Params..., OtherParams...>::type;
  32.  
  33. template <typename... OtherParams>
  34. using type = typename curried<OtherParams...>::type;
  35.  
  36. template <typename... NewParams>
  37. using apply = Currying<curried, NewParams...>;
  38. };
  39.  
  40. template<typename T>
  41. struct Test1
  42. {
  43. using type = int;
  44. };
  45.  
  46. template<typename T, typename T1>
  47. struct Test2
  48. {
  49. using type = char*;
  50. };
  51.  
  52. template <typename T>
  53. void print_type(T t)
  54. {
  55. std::cout << typeid(t).name() << std::endl;
  56. }
  57.  
  58. int main()
  59. {
  60. print_type(Currying<Test1>::type<int>{});
  61. print_type(Currying<Test1>::apply<int>::type<>{});
  62. print_type(Currying<Test2>::type<int, char>{});
  63. print_type(Currying<Test2>::apply<int>::type<char>{});
  64. print_type(Currying<Test2>::apply<int>::apply<char>::type<>{});
  65. print_type(Currying<Test2>::apply<int, char>::type<>{});
  66. return 0;
  67. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
i
i
Pc
Pc
Pc
Pc