4 ms·
In C++11 you can push the return type to the right, like this: auto foo(int x) -> bool;
by cageface 14y ago
In C++11 you can push the return type to the right, like this:
auto foo(int x) -> bool;
- akkartik 14y agoEwww. WTF?! http://www.cprogramming.com/c++11/c++11-auto-decltype-return-value-after-function.html http://www.cprogramming.com/c++11/c++11-auto-decltype-return... provides a rationale: so you don't have to type in ClassName:: twice. Is that really worth this monstrosity? The function name is still not at the start of the statement. '->' is being horribly misused. Anybody know if there's a better reason for this? Did the committee really have nothing better to think about?
- kzrdude 14y agoYes there are much better reasons: http://www2.research.att.com/~bs/C++0xFAQ.html#suffix-return http://www2.research.att.com/~bs/C++0xFAQ.html#suffix-return template<class T, class U> auto mul(T x, U y) -> decltype(x*y) { return x*y; }
- akkartik 14y agoAh, that use case makes sense. I wish the syntax was congruent with C++, but that complaint has been done to death.