ResultOf a function with C++11

Using std::result_of requires you to specify the function argument types. Which is not very practical when you don’t know the function signature. Happily @potatoswatter (David Krauss) over at Stack Overflow pointed out to me that std::function provides the desired functionality:

template< class Func >
struct ResultOf
{
    typedef typename std::function<
        typename std::remove_pointer<Func>::type
        >::result_type T;
};

Mainly, this saves one from writing a large number of partial specializations for Visual C++ 10.0, which lacks support for C++11 variadic templates.

– Enjoy!

About these ads

One comment on “ResultOf a function with C++11

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s