fork download
  1. namespace mpl
  2. {
  3.  
  4. namespace detail
  5. {
  6.  
  7. template < typename... >
  8. struct tuple_;
  9.  
  10. } // namespace detail
  11.  
  12. template < unsigned int x >
  13. struct arg
  14. {
  15. static constexpr unsigned int value = x;
  16. };
  17.  
  18. typedef arg< 1 > _1;
  19.  
  20. template < typename F, typename... T >
  21. struct apply
  22. {
  23. typedef typename F::template apply<
  24. typename F::template replace< T... >::type >::type type;
  25. };
  26.  
  27. template < typename T >
  28. struct lambda;
  29.  
  30. template < template < typename... > class F, typename... Args >
  31. struct lambda< F< Args... > >
  32. {
  33. template < typename >
  34. struct apply;
  35.  
  36. template < typename... T >
  37. struct apply< detail::tuple_< T... > >
  38. {
  39. typedef typename F< T... >::type type;
  40. };
  41.  
  42. template < typename P, typename... T >
  43. struct replace_detail
  44. {
  45. template < unsigned int, typename U, typename... >
  46. struct replace_impl
  47. {
  48. typedef U type;
  49. };
  50.  
  51. template < unsigned int n, unsigned int x,
  52. typename Head, typename... Tail >
  53. struct replace_impl< n, arg< x >, Head, Tail... >
  54. : public replace_impl< n + 1, arg< x >, Tail... > {};
  55.  
  56. template < unsigned int x, typename Head, typename... Tail >
  57. struct replace_impl< x, arg< x >, Head, Tail... >
  58. {
  59. typedef Head type;
  60. };
  61.  
  62. typedef typename replace_impl< 1, P, T... >::type type;
  63. };
  64.  
  65. template < typename... T >
  66. struct replace
  67. {
  68. typedef detail::tuple_< typename replace_detail< Args, T... >::type... > type;
  69. };
  70. };
  71.  
  72. } // namespace mpl
  73.  
  74. template < typename T >
  75. struct add_pointer
  76. { typedef T * type; };
  77.  
  78. template < typename, typename >
  79. struct is_same
  80. {
  81. static constexpr bool value = false;
  82. };
  83.  
  84. template < typename T >
  85. struct is_same< T, T >
  86. {
  87. static constexpr bool value = true;
  88. };
  89.  
  90. static_assert(
  91. is_same<
  92. mpl::apply<
  93. mpl::lambda< add_pointer< mpl::_1 > >,
  94. int >::type,
  95. int * >::value, "types are not same" );
  96.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: ld returned 1 exit status
stdout
Standard output is empty