Turi Create  4.0
turi::toolkit_function_wrapper_impl::result_of_function_wrapper< T > Struct Template Reference

#include <model_server/lib/toolkit_function_wrapper_impl.hpp>

Detailed Description

template<typename T>
struct turi::toolkit_function_wrapper_impl::result_of_function_wrapper< T >

Provides a wrapper around the return type of a function call. For instance:

int test() {
...
}
typedef boost::function_traits<decltype(test)> fntraits;
result_of_function_wrapper<fntraits::result_type> res;
res.call(test);
// after which res.ret_value will contain the return value of res
// (which is an int).

The key reason for this struct is to handle the void return case where the result type of the function is void. This struct specializes that case by making ret_value an integer which is 0 prior to calling the function, and 1 after successful calling of the function.

i.e.

void nothing() {
...
}
typedef boost::function_traits<decltype(nothing)> fntraits;
result_of_function_wrapper<fntraits::result_type> res;
// at this point res.ret_value is an integer and has value 0
try {
res.call(nothing);
} catch (...) {
// function was called, but it didn't return properly,
// res.ret_value is still 0
}
// function call was completed successfully. res.ret_value == 1

Note that the function must take no arguments. If there are arguments, it can be wrapped in a lambda. For instance:

void has_arguments(int) {
...
}
typedef boost::function_traits<decltype(has_arguments)> fntraits;
result_of_function_wrapper<fntraits::result_type> res;
res.call([](){ return has_arguments(5);});

Definition at line 112 of file toolkit_function_wrapper_impl.hpp.


The documentation for this struct was generated from the following file: