Is there anyway in C++ to avoid specifying the return type of a function?
Say you have a function like
auto Foo(arguments) -> decltype(complicated expression here)
{
return complicated expression here;
}
The problem is that you have to repeat the complicated expression twice, which violates the principle of Don't Repeat Yourself. Is there anyway to avoid this? The only thing I can think of is to use a macro, but preprocessor macros are generally an ugly solution and it makes the code less readable as well.
I trust exceptions about as far as I can throw them.
I would say having to specify the type is a good thing. It allows the compiler to complain if you are not returning the type you think you are returning. Also, people using your function sometimes can get away with reading the prototype only, and a prototype of a function that returns "auto" wouldn't be very informative.