Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <tuple>
- template<typename T>
- struct function_traits;
- template<typename R, typename ...Args>
- struct function_traits<R(Args...)>
- {
- typedef R return_type;
- struct args{
- template <size_t i>
- using type = typename std::tuple_element<i, std::tuple<Args...>>::type;
- static const size_t count = sizeof...(Args);
- };
- };
- int f(int a){
- return a;
- }
- double e(int a, double c){
- return a + c;
- }
- int main(int , char **){
- //declare a with same type as return type from f
- function_traits<decltype(f)>::return_type a;
- //declare first with same type as first argument of e
- //declare second with same type as second argument of e
- function_traits<decltype(e)>::args::type<0> first;
- function_traits<decltype(e)>::args::type<1> second;
- std::cout << "Function e have" << function_traits<decltype(e)>::args::count << " parameter/s";
- std::cout << std::is_same< function_traits<decltype(f)>::args::type<0>, int >::value << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment