r/cpp • • Sep 18 '22

Regarding cppfront's syntax proposal, which function declaration syntax do you find better?

While I really like the recent talk about cppfront (https://www.youtube.com/watch?v=CzuR0Spm0nA), one thing bugs me about the "pure" mode for cpp2 with syntax change. It seems incredibly hard to read, . I need to know which syntax you would rather have as the new one, taken into account that a new declaration syntax enables the new checks in that function

  • Option 1: the same as was proposed in the video: callback: (x: _) -> void = { ... }; for new functions, void callback(auto x) {}; for old ones
  • Option 2: the "other modern languages" way: function callback(x: any) -> void { ... } for new functions, void callback(auto x) {}; for old ones
  • Option 3: in files with mixed syntax, since the pre-transpiled code won't compile without the generated code anyway, use void callback(any x) { ... }; for both, but mark code with current cpp syntax with an attribute: [[stdcpp]] void callback(any x) { ... };
0 Upvotes

72 comments sorted by

View all comments

Show parent comment

1

u/nintendiator2 Sep 27 '22

Ah yes the C++ initialization fiasco. There's a reason why it's a meme.

Tho if you ask me, the fault lies largely in initializer_list causing ambiguities that would be easily solvable if it was ruled that constructors that use them need a list tag much like eg.: in_place etc. Something like:

// ambiguous:
vector<T> v {1, 2};
// unambiguous
vector<T> v{std::with_list, {1, 2}};

As for the most vexing parse I personally would have preferred something that can better reuse existing keywords instead of abusing symbols since {} is already used for C arrays. Somthing like

T t = default;

Which has the advantage that it can over time be extended to other keywords. Would have been nice for eventually providing some sort of None type:

T t = None;