Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ auto function return?

Tags:

c++

lately I've seen some code with functions labeled like this:

auto Function(...) -> BOOL

Is there some difference between using just

BOOL Function(...)

The first one looks nicer to me though, maybe I'm just weird, so is it just visual, or it has some other benefits?

like image 536
Martin Prince Avatar asked Dec 13 '22 16:12

Martin Prince


1 Answers

Is there some difference between using just [...]

No - in your particular example, they are equivalent.


it just visual, or it has some other benefits?

Trailing return types have a few benefits:

  • Easier to switch to automatic return type deduction in the future (just delete everything after ->)

  • Can use parameters as part of the return type

  • Can access class C type aliases without having to say C::

In your particular example, these do not apply.

like image 127
Vittorio Romeo Avatar answered Dec 25 '22 23:12

Vittorio Romeo