boost::function_types::result_type使用示例
boost::function_types是C++ Boost库中的一个模板元编程工具库,用来提取函数类型的各个信息。而其中的result_type则可以用于提取函数返回值的类型,下面是一个简单的使用示例。
假设我们有以下两个函数:
int foo(double x) { return static_cast<int>(x); }
std::string bar(long y) { return std::to_string(y); }
我们可以使用boost::function_types::result_type来提取它们的返回值类型,可以仿照如下方式进行:
#include <boost/function_types/result_type.hpp>
#include <type_traits>
int main() {
using FooResultType = boost::function_types::result_type<decltype(foo)>::type;
static_assert(std::is_same_v<FooResultType, int>, "Unexpected result type");