c++ - Is it possible to get the return type of a function without passing arguments to it? -


obviously, can return type of function decltype(foo()), if foo takes arguments won't work, you'd have pass dummy arguments foo in order work. but, there way return type of function without having pass arguments?

supposing return type not depend on argument type (in case should use std::result_of, have provide type of arguments), can write simple type trait lets deduce return type function type:

#include <type_traits>  template<typename t> struct return_type;  template<typename r, typename... args> struct return_type<r(args...)> {     using type = r; };  int foo(double, int);  int main() {     using return_of_foo = return_type<decltype(foo)>::type;     static_assert(std::is_same<return_of_foo, int>::value, "!"); } 

Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -