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
Consider a real production environment: many functions and unit tests all interdependent on the return type of foo()
. Now suppose that the return type needs to change for whatever reason.
If the return type is auto
everywhere, and callers to foo()
and related functions use auto
when getting the returned value, the changes that need to be made are minimal. If not, this could mean hours of extremely tedious and error-prone work.
As a real-world example, I was asked to change a module from using raw pointers everywhere to smart pointers. Fixing the unit tests was more painful than the actual code.
While there are other ways this could be handled, the use of auto
return types seems like a good fit.