C++ Modules: Getting Started Today - Andreas Weis - CppCon 2023

preview_player
Показать описание
---

C++ Modules: Getting Started Today - Andreas Weis - CppCon 2023

Modules have been one of the most highly anticipated features of C++20. Unfortunately, it was also the language feature that took the longest to become widely available for developers to use. This year, for the first time, we see broad support for the feature in all major compilers and mainstream build system support through CMake. The goal of this talk is to provide you with all the basic knowledge to allow you getting started with C++20 modules today.

We will take a look at how modules change the build process and why it took so long to implement them. We will take a tour of the essentials of the named modules mechanism and explore the new best practices for physical code structure in a modules-based code base, including how to set up a build with CMake. And last but not least, we will discuss different options for interacting with existing header-based code.

The talk will focus above all else on practicality: We will only be covering features that are widely available for use today with the latest compilers and build tools. We will give special attention to the areas where the design practices for modules differ from the familiar header-based approach and address common misconceptions and pitfalls that are typical among developers first encountering the feature. No prior knowledge of modules is required.
---

Andreas Weis

Andreas Weis has been writing C++ code in many different domains, from real-time graphics, to distributed applications, to embedded systems. As a library writer by nature, he enjoys writing portable code and exposing complex functionalities through simple, richly-typed interfaces. Both of which C++ allows him to do extensively. Andreas is also one of the co-organizers of the Munich C++ User Group, which allows him to share this passion with others on a regular basis.

He currently works for Woven by Toyota, where he focuses on building modern software for use in safety critical systems.
---

---

#cppcon #cppprogramming #cpp
Рекомендации по теме
Комментарии
Автор

Great talk, the include guard trick is genius!

christiandaley
Автор

The best talk on modules thus far at CppCon

davidsicilia
Автор

Awesome! I've been looking for a good first talk on modules and in particular what I can do right now. The standard is very nice, but it seems a lot of module features haven't been implemented yet, which makes it quite annoying when I watch a lot of talks, they don't take that into account.

vesk
Автор

A small error on the slides: The CMake FILE_SET for modules sources is called CXX_MODULES, not MODULES.

Also, on slide #20 about interface partitions, the names of the module in the primary module interface and the partitions need to be consistent (either all 'm' or all 'mice', but not a mixture of the two).

ComicSansMS
Автор

Great talk, really helpful. Thank you!

fzort
Автор

Only C++ can take a concept this simple and make it hard

NotherPleb
Автор

Is 17:53 correct? My compiler thinks that the implementaiton module is trying to import itself. Oh wait, the code is correct but the compilation order is crucial, as was not mentioned. 21:29 should the "m:" twice be "mice:"?

victoreijkhout
Автор

this reminds me of a helmet that i had that had a hammer attached to it. So everytime i want to nail something to the wall, i would wear that helmet and swing my head around to hit the nail.

but sometimes i miss and i hit my head against the wall instead. So to solve that problem, i added some padding to my forehead.
now everything works like a charm.

zahash
Автор

Happy to have learnt through this talk how to export templates. I was putting the export on the function "part" and couldn't figure out why it wasn't working.

MathewBensonCodes
Автор

Was just wondering if modules are ready to play around with yet. I knew 5 years in was way too soon to check. oh well. maybe my grandchildren will love them

Quazgaa
Автор

At this time (version 17.8.6) Visual Studio can with no problem have modules that wrap header files that include the C standard library. So, no problem if you write a module that uses a C library. That's already a big deal.
It won't work if you include a header that includes the C++ standard library. So if you try to wrap a C++ library that won't work because the library will include stuff from the C++ standard library and you will get name clashes.
So, the solution is to have an immediate wrapper module that just includes all standard library headers that are used by the wrapped library in the bit between module; and export module x;. and then exports the library. In most cases that will probably approach most of the C++ standard library. At least it's a trick that works (I verified with a minimal example). Hopefully this issue will be resolved and the trick will no longer be needed soon.

theo-drdz
Автор

In my_module_p{1, 2}.cpp, you have "export module m:something;"... what is m? I don't see you declaring a module called m. Should it be mice instead?

Fetrovsky
Автор

Has anyone figured out if intellisense work now with vscode + cmake + ninja? Still getting module not found errors

arsalananwari
Автор

Aside of CMake (as of 3.28) modules support by toolchains is very lacking. Neither Apple's clang 15.0 nor gcc 13.2 provide a dependency graph for CMake. clang 17.0 works somewhat with CMake (i.e. it configures and builts everything), but then VS Code can't handle dependencies and code completion, neither with the C/C++ plugin nor the clangd plugin. So for the time being it seems we have to wait for the tools to adopt still. "Getting started today"? No way.

olafschluter
Автор

...um @19:02, the mice!!! become m?!!!, Why?

liveonphoenix
Автор

I don't like the fact imports are dumped into the current namespace. Perhaps if it was a bit more python-y in the way of : import B; B.my_import_func(); in lieu of a using declaration would provide a much cleaner namespace .

abdulshabazz
Автор

It looks so much complex than the other languages module systems...

kiddkai
Автор

With concepts, templates shouldn't be a problem yes?

chukwujiobicanon
Автор

Been waiting for proper modules support outside MSVC for so many years now. Build tool chain environment still convoluted. State of affairs is just so sad. C++ is such a good language otherwise.

bobsinclair
Автор

I'm using visual studio and start to learn modules. The thing is there is bad tutorial on the internet. I import std module to other module that is in project which compile to static library (.lib). In that project I'm only using print function from cpp23. The lib file is about 4mb of size when using imported std. If this is normal? All library contining cpp standard library is linked to my library? Second, if I will link my library with other project that make executable file (.exe) and in that project I'm using cpp standard library (import std) ofcourse I' have to use std.ifc interface again but do I have link c++ standard library (.lib) files again? This is very practical information..not only to show how "nice" is write "import std".

witM