In the Wikipedia article decltype http://en.wikipedia.org/wiki/Decltype I came across this example:
int& foo(int& i); float foo(float& f); template <class T> auto transparent_forwarder(T& t) β> decltype(foo(t)) { return foo(t); }
Although I understood the motive of this function, I did not understand the syntax that it uses, and in particular -> in the declaration. What is β and how is it interpreted?
EDIT 1
Based on the foregoing: what is wrong here?
template <typename T1, typename T2> auto sum(T1 v1, T2 v2) -> decltype(v1 + v2) { return v1 + v2; }
Error:
error: expected type-specifier before 'decltype' error: expected initializer before 'decltype
Answer to EDIT 1:
OOPS! I forgot to use the -std=c++11 compiler option in g ++.
EDIT 2
Based on the answer below. I have a related question: See the declaration below:
template <typename T1, typename T2> decltype(*(T1 *) nullptr + *(T2 *) nullptr) sum2(T1 v1, T2 v2);
It uses decltype without the need of a -> function declaration. So why do we need ->
footy source share