Can the return type of the function be obtained from within the function?

Can the return type of a function be obtained in a simple way within the function?

For example, given:

template <typename P>
static inline auto foo(P p) -> typename std::remove_reference<decltype(*p)>::type {
typename std::remove_reference<decltype(*p)>::type f{}; // <-- here

...
}


In C++11 can I refer to the big nasty return type of foo, within foo itself, without repeating it, at the line marked // <-- here?

Call the function with a decltype.

decltype(foo(p)) f{};

Comments

Popular posts from this blog

Meaning of `{}` for return expression

Get current scroll position of ScrollView in React Native

flutter websocket connection issue