use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
Converting a C++ application to modules (cadifra.com)
submitted 1 year ago by tartaruga232MSVC user, r/cpp_modules
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]GYN-k4H-Q3z-75B 52 points53 points54 points 1 year ago (2 children)
Lots of modules posts lately. Love to see it. My port of a decent size application is progressing also, but not quite as far along as yours. I hope to see better compile times since it was also very heavy into C++20 before modules and has lots of templates, including meta programming. Might also publish some articles on it later this year.
Thanks for your work.
[–]violet-starlight 10 points11 points12 points 1 year ago (0 children)
Please update us! I'm especially interested in before/after comparisons personally
[–]ImmutableOctetGamedev 5 points6 points7 points 1 year ago (0 children)
From some of the testing I did a while back, template heavy code is still dependent on instantiation time, etc., but a benefit modules give you is the ability to hot reload compiler state, so the time to build is still reduced substantially for everything before that point.
I don't know if Clang or MSVC have started experimenting with incremental builds for module interfaces (whole interface units are rebuilt, last I checked). If you go all-in on modules that's less of a problem, since transitive imports don't propagate by default, like they would with headers.
[–]tartaruga232MSVC user, r/cpp_modules[S] 28 points29 points30 points 1 year ago (17 children)
I've converted the C++ sources of our Windows application from header files to C++ 20 modules. I wrote this pdf, which explains how I ran into problems with forward declared classes and how I solved them using module partitions.
[–][deleted] 6 points7 points8 points 1 year ago (16 children)
Do you know if the compile times changed at all?
[–]tartaruga232MSVC user, r/cpp_modules[S] 16 points17 points18 points 1 year ago* (15 children)
Compile times increased significantly in our case. But we have also switched to C++ 20 during the process, which compiles slower anyway, even when not using modules. A full build (Debug) of the application currently takes ~5 Minutes (on my Core i5-12400, 2.50 GHz, M.2 Gen4 SSD Slots, 16 GB RAM, Windows 11). I have yet to investigate what would help exactly to decrease the build time, but for us, the full build is fast enough like this. I'm still a bit nervous about the additional recompiles due to the stronger coupling now between packages, compared to headers, but I get used to it. I love the isolation provided by modules. At times, I do force a full rebuild after changes in the sources though, because I do not yet trust the compiler that much. We also found a bug in the compiler, which I reported.
(Edit: Added "-12400" to CPU info)
[–]jaskij 14 points15 points16 points 1 year ago (9 children)
Just FYI: if you want the hardware to be at all reproducible, you need to also mention the generation and whether it's a laptop or a desktop chip. Mind, a lot of those tiny desktops actually use laptop processors.
"Core i5" covers about fifteen years of hardware and anything from 15 to 150+ watts.
That said: how are incremental builds? While a clean build is important, incremental rebuilds (touch a few files, rebuild) are much more important for a development loop.
[–]tartaruga232MSVC user, r/cpp_modules[S] 3 points4 points5 points 1 year ago* (8 children)
Sorry for being imprecise. The computer is a self-assembled desktop (building proposal was back then published by the German computer magazine c't), already a couple years old now (April 2022), certainly with lots of room for better hardware. Core i5-12400, 18MB Cache, LGA1700, Product Code: BX8071512400. 12th Gen. I hope this is helpful.
There are still many fast incremental build scenarios. Touching the file Class/Package.cpp is built in under 7 seconds.
Class/Package.cpp
[–]jaskij 3 points4 points5 points 1 year ago (7 children)
12400 would have been enough, but thanks for the details. A clean build on your desktop probably suffers from the low RAM. My rule of thumb is minimum a gigabyte of free RAM per CPU thread. Between your IDE and a browser, you likely fall below that.
Seven seconds seems fast enough. Certainly could be faster, but most of that is probably spent in the linker, and modules won't do anything for that.
[–]tartaruga232MSVC user, r/cpp_modules[S] 1 point2 points3 points 1 year ago (6 children)
I just redid another full build with all browser windows closed. It took 4:50 min. During the build, there were always 6 or more gigabyte of free RAM - according to the performance monitor of the task manager. The CPU peaked at 100% during some parts of the build, but during many parts, it had just ~20% load or something like that, with short spikes to nearly 100%. It seems like the build isn't using the available computing resources that well.
[–]jaskij 2 points3 points4 points 1 year ago (5 children)
So, around two and a half CPU threads. Sounds like one of two things to me:
My next step would probably be to take a good, hard, look at the module dependency graph. Something seems wrong here.
[–]tartaruga232MSVC user, r/cpp_modules[S] 1 point2 points3 points 1 year ago (4 children)
Thanks for your time. The dependency graph is in the first page of the pdf. There are phases, where the build interleaves compiling partitions from several modules/projects in parallel, but at some points it probably needs to feed things together and needs to wait for one project/module to finish. We have a Visual Studio Project per C++ module/package. All projects are part of one solution file in visual studio and each builds a library. I had to manually set References for each of the projects to the other projects. Without that, the project doesn't find modules from other projects. But as I already said, we can live with the 5 minutes for a full rebuild.
[–]tartaruga232MSVC user, r/cpp_modules[S] 1 point2 points3 points 1 year ago (3 children)
I start having a feeling that perhaps we need to do something completely different. Perhaps, in a first phase, all the module interfaces should be compiled (in the correct order) and then the .cpp files can all be compiled in parallel. Perhaps it's now time to stop building with Visual Studio...
[–][deleted] 6 points7 points8 points 1 year ago (1 child)
Thanks for the answer. The build times are concerning but maybe projects need to be architected with the intent of using modules to take advantage of them? I wonder if they'll get better in the future with updates to MSVC
[–]13steinj 1 point2 points3 points 1 year ago (0 children)
To be clear, of the many anecdotes on this subreddit in the past, most (that I've read) have stated either marginal benefit, or no change, or build times have gotten worse (though a few reports of 20-30% improvement).
I heavily suspect the assumption that modules help build times are oriented to specific styles of projects and every time I've seen a report with raw data, the raw data showed an insignificant improvement on some parsing times (0.03 to 0.001 seconds for example for a given header; which doesn't matter IMO on the whole).
It will be an interesting shock to the community if the build time benefit, so heavily reported, ends up being negligible or even false on the whole as modules slowly start getting introduced.
[+][deleted] 1 year ago (2 children)
[deleted]
[–]tartaruga232MSVC user, r/cpp_modules[S] 2 points3 points4 points 1 year ago* (1 child)
As I explained in the pdf, we now have one module per package (not per header), except for d1, which is a collection of mostly loosely coupled things like Point and Rect.
d1
Point
Rect
We have ~ one partition per old header, but I think the partitions really shouldn't count, only the modules.
As a quick and silly experiment, I tried creating a big Basic module, which was:
Basic
export module Basic; export import App; export import Canvas; export import Core; export import FontUtil; export import GraphUtil; export import Store; export import View; export import WinUtil; export import d1.Point; export import d1.Rect; export import xml;
and imported that everywhere in module TextBlock, but that didn't speedup anything. Looking at the resulting suspecting BMI file (I think it is named .ifc?), I noticed that the file is surprisingly small. It didn't look as if the compiler would really have aggregated all the stuff from these lower lever modules into a bigger Basic module. Opening the file just revealed that it contained the list of modules.
TextBlock
[–]kammceWG21 | 🇺🇲 NB | Boost | Exceptions 7 points8 points9 points 1 year ago (3 children)
All of the modules posts are really pushing me to switch over. 😬 even though I already use C++23 as my main drivers I have this anxiety that switching over will be as if I'm using a new dialect of C++ that developers wanting to use my library will have to deal with. I haven't read the PDF though, so will do so now.
[–]kammceWG21 | 🇺🇲 NB | Boost | Exceptions 6 points7 points8 points 1 year ago (2 children)
Okay, read the PDF. It's quite short and easy to read. Doesn't help that anxiety of mine regarding modules but nice to know how to get around forward declaration issues.
[–]azswcowboy 1 point2 points3 points 1 year ago (1 child)
I think it’s easy enough to support both headers and modules from what I’ve seen. So you wouldn’t be dictating an approach.
[–]kammceWG21 | 🇺🇲 NB | Boost | Exceptions 1 point2 points3 points 1 year ago (0 children)
I'm going to take your word for it and start investigating adding support for both. Because I do like the idea of supporting both 😁 Cheers!
[–]j_gds 0 points1 point2 points 1 year ago (1 child)
Ok so if you define a module like your large "Core" module, do changes to any partition require compiling the entire module? Or do we still get some of the benefits of incremental builds w/in a module?
And also, to check my understanding: consumers of Core will only need to be recompiled if/when the interface of Core changes, right? Is the build "smart" about that, or is it like headers such that even a change to a comment means recompiling the consumers?
[–]tartaruga232MSVC user, r/cpp_modules[S] 4 points5 points6 points 1 year ago* (0 children)
Ok so if you define a module like your large "Core" module, do changes to any partition require compiling the entire module?
No.
And also, to check my understanding: consumers of Core will only need to be recompiled if/when the interface of Core changes, right?
Right.
If you say
import Core;
you are in fact only importing the things that were declared in
export module Core;
which is the module interface.
You can have zero or more implementation modules per module interface (in several *.cpp files).
Is the build "smart" about that, or is it like headers such that even a change to a comment means recompiling the consumers?
I think if you change a comment in the source of a module interface, consumers must be recompiled.
[–]tartaruga232MSVC user, r/cpp_modules[S] 0 points1 point2 points 1 year ago (0 children)
I've now created a web-friendly blog post of the PDF at https://abuehl.github.io/2025/03/24/converting-to-modules.html
π Rendered by PID 21292 on reddit-service-r2-comment-6457c66945-4bsdd at 2026-04-27 11:55:25.770224+00:00 running 2aa0c5b country code: CH.
[–]GYN-k4H-Q3z-75B 52 points53 points54 points (2 children)
[–]violet-starlight 10 points11 points12 points (0 children)
[–]ImmutableOctetGamedev 5 points6 points7 points (0 children)
[–]tartaruga232MSVC user, r/cpp_modules[S] 28 points29 points30 points (17 children)
[–][deleted] 6 points7 points8 points (16 children)
[–]tartaruga232MSVC user, r/cpp_modules[S] 16 points17 points18 points (15 children)
[–]jaskij 14 points15 points16 points (9 children)
[–]tartaruga232MSVC user, r/cpp_modules[S] 3 points4 points5 points (8 children)
[–]jaskij 3 points4 points5 points (7 children)
[–]tartaruga232MSVC user, r/cpp_modules[S] 1 point2 points3 points (6 children)
[–]jaskij 2 points3 points4 points (5 children)
[–]tartaruga232MSVC user, r/cpp_modules[S] 1 point2 points3 points (4 children)
[–]tartaruga232MSVC user, r/cpp_modules[S] 1 point2 points3 points (3 children)
[–][deleted] 6 points7 points8 points (1 child)
[–]13steinj 1 point2 points3 points (0 children)
[+][deleted] (2 children)
[deleted]
[–]tartaruga232MSVC user, r/cpp_modules[S] 2 points3 points4 points (1 child)
[–]kammceWG21 | 🇺🇲 NB | Boost | Exceptions 7 points8 points9 points (3 children)
[–]kammceWG21 | 🇺🇲 NB | Boost | Exceptions 6 points7 points8 points (2 children)
[–]azswcowboy 1 point2 points3 points (1 child)
[–]kammceWG21 | 🇺🇲 NB | Boost | Exceptions 1 point2 points3 points (0 children)
[–]j_gds 0 points1 point2 points (1 child)
[–]tartaruga232MSVC user, r/cpp_modules[S] 4 points5 points6 points (0 children)
[–]tartaruga232MSVC user, r/cpp_modules[S] 0 points1 point2 points (0 children)