c++gccboostdecltypedeclval

How should this c++ typedef using decltype and declval be written to make it portable?


I have the following

template <typename F, typename A0>
struct ResultOf {
        typedef typename decltype(boost::declval<F>()(boost::declval<A0>())) Type;
};

It was written so that VS2010 could have a result_of that worked for a specific use case. It is working under vs2015, vs2013 and vs2010 but under gcc I get a compile error

error: expected nested-name-specifier before ‘decltype’
typedef typename decltype(boost::declval<F>()(boost::declval<A0>())) Type;

Is there an obvious small fix here?


Solution

  • typename keyword is not needed here. It is used, in particular, to denote a dependent type, like T::value_type, when a compiler cannot know whether value_type is a type. There are no dependent types in the present case.