fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <type_traits>
  4.  
  5. template <typename T>
  6. struct Identity
  7. {
  8. typedef T result;
  9. };
  10.  
  11. template <typename T, T v>
  12. struct Constant
  13. {
  14. typedef T type;
  15. static constexpr T value = v;
  16. };
  17.  
  18. template <int N>
  19. using Int = Constant<int, N>;
  20.  
  21. template <template <typename, typename, typename...> class function, typename arg2>
  22. struct bind2nd
  23. {
  24. template <typename arg1, typename... args>
  25. struct result : function<arg1, arg2, args...>
  26. {};
  27. };
  28.  
  29. template <typename left, typename right>
  30. struct plus : Identity<Constant<decltype(left::value + right::value), left::value + right::value>>
  31. {};
  32.  
  33. template <typename arg>
  34. struct plus1 : bind2nd<plus, Int<1>>::template result<arg>
  35. {};
  36.  
  37. int main()
  38. {
  39. std::cout << std::boolalpha << std::is_same<plus1<Int<100>>::result, Int<101>>::value;
  40. }
Success #stdin #stdout 0s 2896KB
stdin
Standard input is empty
stdout
false