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

  • A+
Category:Languages

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{}; 

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: