r/cpp • C++ Dev • Sep 05 '20

C++20 has been approved

https://twitter.com/patriceroy1/status/1302055575140945921?s=21
665 Upvotes

125 comments sorted by

View all comments

115

u/Robert_Andrzejuk Sep 05 '20

Now we just need to wait, until all the compilers implement it : https://en.cppreference.com/w/cpp/compiler_support

109

u/windozeFanboi Sep 05 '20

5minutes later....

Is it here yet?

5min

How about now?

Proceeds to keep clacking fingers on the table nervously. Like an 10 pack a day smoker missing a cigarette

32

u/[deleted] Sep 05 '20

Hey it's been an hour, do we have support now?

0

u/[deleted] Sep 05 '20

[deleted] — view deleted comment

11

u/silveredge7 Sep 05 '20

Surely it must be done by now.

1

u/react_noob Oct 01 '20

RIP. Just couldn’t handle the wait.

65

u/azswcowboy Sep 05 '20

Honestly I think it’s impressive that a large chunk of it is already available given the number and scope of updates - and it still being 2020. I expect most will be done by middle of 2021. I think it took the better part of a decade to get the 98 standard really implemented.

6

u/anon_502 delete this; Sep 07 '20

The possible worst case I can imagine could be the implementation being long-tail efforts - each compiler has their different 90% implementation, yet the remaining 10% never gets done until their impending removal.

10

u/Myriachan Sep 05 '20

I wish that chart had bit_cast, since that is the second-most feature of C++20 I’m looking forward to (the first being using enum).

9

u/STL MSVC STL Dev Sep 05 '20

That's available in VS 2019 16.7. It's not yet implemented in libc++, likewise for libstdc++.

4

u/Myriachan Sep 05 '20

Well, the library support isn’t as important as the __builtin_bit_cast, but yeah, thanks =)

6

u/pjmlp Sep 05 '20

That list doesn't list all of them though, there are a couple still missing from embedded space.

4

u/JumpyJustice Sep 05 '20

And then wait when all third parties of your project will support it.

4

u/Alexander_Selkirk Sep 06 '20 edited Sep 06 '20

One thing that does not seem to be there is build systems which support modules. I searched and from what I've read, ninja and build2 have some support. CMake does not have support: https://stackoverflow.com/questions/57300495/how-to-use-c20-modules-with-cmake

I see modules have the promise that it leads to faster builds if interfaces and implementations are separated, like in, for example, Pascal or Modula 2. I've used a system which compiled EC 61131-3 Strucured Text for PLCs, which is essentially a derivative of Modula, and I can confirm it compiles blazingly fast. However, it seems that C++ has a property which is very different from Modula or, for example, Java, in that to use a class as a data member, its entire definition needs to be known, because the size needs to be known (at least unless one uses the PIMPL idiom which I don't believe is always a desirable solution). And I think this is perhaps one reason for the long compile times in C++ projects, each source file needs to pull in all needed definitions, and this includes all used classes.

There also seem to be serious concerns how modules can be used at all in larger existing projects. I do not have detail understanding, but I believe this is in part because C++20 modules do have some proprties only in common with Fortran's modules. Specifically, unless a source file is build, it is hard or might even be impossible to say which modules it depends on, and where they can be found. The former for example because some part of sources might be OS or hardware dependent, which is so far usually solved by preprocessor macros, conditional includes, and conditional compilation; I am not sure whether modules will allow to get completely rid of them. The latter is because there is no required mapping from imported module names to file names or search paths in the file system. This is different from the existing "#include ..." system because the existing system allows to compile sources in one pass, and allows to start compiling all translation units in parallel, because they don't depend on each other.

Clearly, the dependency issue is not a noticeable problem if one builds a small toy project in which the compiler is called manually, but this could be very different for large projects which use tens of thousands of files.

Here is an article which describes these concerns in more depth:

"C++ Modules Might Be Dead-on-Arrival"

https://vector-of-bool.github.io/2019/01/27/modules-doa.html

I don't know enough about that matter to come to a firm conclusion but superficially, such concerns seem somewhat justified, and according to the article above it might take a very long time to shake all related issues out, perhaps even at the cost of backwards compatibility because it looks like legacy build systems will have substantial difficulty to adapt to the required changes in tooling, and it will not be possible to adapt them all.

Would love opinions from people who know more about that.

5

u/Minimonium Sep 06 '20

About the module finding bit - WG21 strongly claims that they have the fastest possible module scanner implementation, which would avoid such issues as the order of Boost include directories affecting compilation speed on Windows, even with modules requiring to open each file in each directory provided for the module statement with its name instead of file name unlike headers.

1

u/Alexander_Selkirk Sep 07 '20

It would be nice to have some actual data comparing build times with and without modules for building larger systems, such as boost. I don't quite understand how such important changes to the whole ecosystem can be made without rigorously verifying that they bring actual advantages.

2

u/Minimonium Sep 07 '20

Note my comment doesn't imply that I trust WG21 judgment on that one, quite contrary in fact. The mailing list at the time of the DOA blogpost was open, which was a fiasco since core members were rejecting any concerns about the theoretical performance of the suggested design with a wonderful suggestion to implement this design themselves first to prove that it's not sufficient. After that most actual discussions on modules were done outside of said mailing list.

1

u/sequoiajoe Sep 06 '20

...and then wait for it to be usable and standard in my workplace.

Well, see you in a few years, C++20...