fork(1) download
  1. #include <iostream>
  2. #include <tuple>
  3. #include <typeinfo>
  4.  
  5. template <typename T>
  6. struct function_traits;
  7.  
  8. struct void_type { using type = void; };
  9.  
  10. template <typename T_Ret, typename ...T_Args>
  11. struct function_traits<T_Ret(T_Args...)> {
  12. // Number of arguments.
  13. enum { arity = sizeof...(T_Args) };
  14.  
  15. // Argument types.
  16. template <size_t i>
  17. struct args {
  18. using type
  19. = typename std::conditional<(i < sizeof...(T_Args)),
  20. std::tuple_element<i, std::tuple<T_Args...>>,
  21. void_type>::type::type;
  22. };
  23. };
  24.  
  25. int main() {
  26. using Arg0 = function_traits<int(float)>::args<0>::type;
  27. using Arg1 = function_traits<int(float)>::args<1>::type;
  28.  
  29. std::cout << typeid(Arg0).name() << std::endl;
  30. std::cout << typeid(Arg1).name() << std::endl;
  31. }
  32.  
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
f
v