Re:Cppfront, Herb Sutter's proposal for a new C++ syntax
by Jtsummers on Saturday September 17, 2022 @02:55PM
(#32880267)
:_ 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.
Re:Cppfront, Herb Sutter's proposal for a new C++ syntax
by gpderetta on Saturday September 17, 2022 @05:39PM
(#32881854)
The syntax:
void hello(auto msg){
...
}
Is legal today (since C++20 IIRC) and it is equivalent to your first example.
Re:Cppfront, Herb Sutter's proposal for a new C++ syntax
by philippejara on Saturday September 17, 2022 @03:46PM
(#32880831)
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...
Re:Cppfront, Herb Sutter's proposal for a new C++ syntax
by int_19h on Sunday September 18, 2022 @06:50PM
(#32892230)
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++.
On another note, anything with "->" is just painful to write, same thing with the (in his proposal) ":_" instead of "=" for function arguments. Just annoying.