1

Having looked at a few online documents on C++14, I found the following syntax for defining a function in C++14 that uses trailing return types:

auto myFunc() -> int {}

my question is, other then using this way for using decltype in the argument and some other scenarios, is there a difference or any benefit for using the above syntax for bog standard functions like:

int myFunc() {}
Praetorian
  • 106,671
  • 19
  • 240
  • 328
SD1990
  • 808
  • 1
  • 11
  • 29
  • No in this case where the type is known and explicit there's no difference. – Some programmer dude Jan 14 '15 at 10:08
  • 3
    related: [Should the trailing return type syntax style become the default for new C++11 programs?](http://stackoverflow.com/q/11215227/3953764) – Piotr Skotnicki Jan 14 '15 at 10:10
  • In C++14 it should become `auto myFunc () { }` anyway. – Bartek Banachewicz Jan 14 '15 at 10:43
  • 1
    @BartekBanachewicz `auto` return types are not yet maturely supported by compilers (e.g. deep chains of recursive function calls require some care in the order of definition, clang disables debug symbol information so valgrind etc. are crippled, and Doxygen doesn't really grok the return type yet). – TemplateRex Jan 14 '15 at 12:12
  • Regardless of whether you use a trailing return type or not, `myFunc` needs to return an `int` :) – Praetorian Jan 14 '15 at 14:42

1 Answers1

3

Argument for : coherence.
This way you don't have the freak function needing a trailing return type standing out.

Argument against : wow that's ugly.[pers. opinion]

Semantic difference : none.

Quentin
  • 62,093
  • 7
  • 131
  • 191