Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

been a bit since I've touched c++, but is there any reason to use trailing return types in that manner aside from solving scope issue with decltype on templates? I assumed this was a way to write functions to deal with that case and not for "regular" functions.

On another note, anything with "->" is just painful to write, same thing with the (in his proposal) ":_" instead of "=" for function arguments. Just annoying.



:_ appears to mark it as a generic type parameter, the `hello` function in the example ought to be equivalent to this straight C++:

  template<typename T>
  void hello(T msg) {
    std::cout << "Hello " << msg << "\n";
  }

  hello: (msg: _) = {
    std::cout << "Hello " << msg << "\n";
  }
I kind of like this, actually, because so many people I've worked with are afraid of templates in C++, but they seem to have no trouble with essentially equivalent code using generics (in other statically typed languages) or dynamically typed languages where it "just works" (until it doesn't). Not that we'll be adopting this any time soon, but I suspect they'd be more amenable to this form when `template` seems to make them quake in their boots.


The syntax:

   void hello(auto msg){
      ...
   }
Is legal today (since C++20 IIRC) and it is equivalent to your first example.


Ah actually missed that, good catch, it does seem to be a step forward in regards to dealing with the syntactical clunkyness of templates. Now if we could have keyword arguments in functions calls without having to deal with some kludge...


I actually prefer trailing return type for the simple reason that they often get very verbose with templates, and then it can be difficult to find the function name in the declaration. With the -> syntax, the function name is always in the same spot visually.

As for -> being painful to write - that's obviously subjective, but more importantly, given that it's the operator you use to access members via pointer-like things (including smart pointers and iterators), it's already pervasive in C++.


You have to use it for lambdas, so using it everywhere makes some code more consistent and readable




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: