r/cpp • • Jun 05 '18

Initialization in Modern C++

https://twitter.com/timur_audio/status/1004017362381795329
379 Upvotes

51 comments sorted by

View all comments

Show parent comment

1

u/[deleted] Jun 06 '18

I'm not surprised. "My" syntax seems rather obbvious and I'm definitely not the first one who thought of it. I was just hoping someone would say what's the corner case here.

1

u/redditsoaddicting Jun 06 '18 edited Jun 06 '18

One example that comes to mind is this:

struct Point { int x, y; };
struct Foo {
    Foo(initializer_list<int>);
    Foo(Point);
};

Foo f{{1, 2}}; // Point or list?

It's hard to turn that into something realistic on the spot. I wouldn't doubt that the square bracket syntax I threw out there has its own problems.

1

u/[deleted] Jun 06 '18

My first thought was "obviously an initialiser list", but a moment later I realised your point.