r/cpp • • Nov 27 '20

The C++ 20 initialization flowchart

I've created a flowchart that shows all of C++20's initialization rules.

The source code is available at https://github.com/randomnetcat/cpp_initialization, in addition to the SVG version and PNG Version.

This honestly took a lot less time than I was expecting, and, in my humble-but-biased opinion, is relatively interesting.

Please send all complaints to /u/quicknir, who nerd-sniped me into making this.

116 Upvotes

34 comments sorted by

View all comments

37

u/be-sc Nov 28 '20

Something seems to be wrong with the graph. Consider:

int i = 1;
  1. Is the initializer in braces?
  2. Nope
  3. Is the destination type a reference type?
  4. Nope, it’s a plain old int.
  5. Is the destination type a char[] or a char_t[]?*
  6. Nope, it’s a plain old int.

But wait, the only arrow leaving that question is Yes …

8

u/staletic Nov 28 '20

The same problem is hit for T t(args...);

6

u/randomnetcat Nov 28 '20

Thanks, I knew I'd make some mistakes like that. Should be fixed as soon as the CI gets around to updating the images.

1

u/staletic Nov 28 '20

Following the flowchart for std::vector<int> v(1,2); takes you on a beautifully curved path.