【发布时间】:2012-07-05 14:41:43
【问题描述】:
可能重复:
Extract the return type of a function without calling it (using templates?)
从这个开始(由其他人提供):
int my_function(int, int *, double);
我想解决这个问题:
typedef boost::function_types::result_type< my_function_type >::type my_result;
typedef boost::function_types::parameter_types< my_function_type >::type my_parameters;
我如何获得my_function_type?
注意:我知道BOOST_TYPEOF(),但它似乎有点吓人,比如“也许不是完全便携”?
【问题讨论】:
-
函数可以重载,还是您明确不想处理这种情况?哦,你可能还需要 C++11。
-
@R.MartinhoFernandes:我可以指定函数是纯“C”风格,因此不会重载。
-
C++11 关键字
decltype将允许您这样做。我认为仅使用 C++03 没有任何简单的方法。 -
@DavidH:我知道你还在等待答案。您在寻找 C++03 解决方案吗?
-
@phresnel:是的,这就是我的想法,尽管我确信这是不可能的。
标签: c++ templates boost c++11 metaprogramming