I'm trying to figure our how I can get some code to compile that will determine the size of T's return value, where T is a function prototype, in my function template.
template<typename T>
void functionReturnLength()
{
long lReturnTypeSize = boost::mpl::eval_if<
boost::is_void<boost::function_types::result_type<T>::type>::value,
boost::mpl::long_<0>,
boost::mpl::long_<boost::mpl::sizeof_<boost::function_types::result_type<T>::type>::value>>::value;
}
However it still does not compile because sizeof(void) is not a valid operation - even though I am trying to construct an if-statement that will return a size of 0 if the type is void. I'm fairly new to BOOST MPL, so, while I have been browsing the documentation for some time, I am not sure how I could apply other ifs like if_ or apply_if, and if these would even work.
Thanks.
You can use your own metafunction
template<typename T>
struct get_size { static const size_t value = sizeof(T); };
template<>
struct get_size<void> { static const size_t value = 0; };
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With