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