With GCC 4.8.0 released, we have a compiler that supports automatic return type deduction, part of C++14. With -std=c++1y
, I can do this:
auto
For scenario 3 I would turn the return type of function signature with the local variable to be returned around. It would make it clearer for client programmers hat the function returns. Like this:
Scenario 3 To prevent redundancy:
std::vector, int>> foo() {
decltype(foo()) ret;
return ret;
}
Yes, it has no auto keyword but the principal is the same to prevent redundancy and give programmers who dont have access to the source an easier time.