I see a lot of this kind of code statements in one of well known C++ unit test framework.
This is inline class member function.
auto exeName() const -> std::string {
return m_exeName;
}
What benefits does it give? Wouldn't it be the same to write
std::string exeName() const {
return m_exeName;
}
I understand what are benefits of trailing return type. But if function returns just string or int or other basic type why we can't just use well known syntax?
It is the only way to do it (explicitly) for lambda:
Benefits comes when using
decltype
:versus
Similarly, with inner types:
versus
Another benefit is with "complex" return type syntax
versus
or
versus
Then consistency with above code.