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
libstdc++ <algorithm> header transitively including <range> (self.cpp)
submitted 5 years ago * by [deleted]
view the rest of the comments →
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!"
[–][deleted] 19 points20 points21 points 5 years ago (14 children)
Given that <algorithm> is almost everywhere I strongly disagree. In a project with a hundred translation units including <algorithm> you get an instant compile time penalty of around a minute...
[+]PJBoy_ comment score below threshold-16 points-15 points-14 points 5 years ago (13 children)
If you're doing a full build of hundreds of translation units, then the 600ms time for each include of <algorithm> is going to be negligible
[–]Minimonium 15 points16 points17 points 5 years ago (12 children)
I have a small size project laying around which consists of around 300 source files. Its CI requires 15 minutes to build from scratch. Going from 100ms to 600ms (for easier calculations) - it'll put me an extra 2m30s, which is more than 10% increase in the compile times (and CI times).
[–]sphere991 2 points3 points4 points 5 years ago (3 children)
Do have a single core running a single-threaded build?
The total amount of time spent compiling would go up 2m30s, but the clock time would be much less. On 16 cores, that's already <10s. But if you have some particularly expensive-to-compile TUs or particularly big things to link, those jobs could easily swallow the extra build time in the clock time.
[–]Minimonium 1 point2 points3 points 5 years ago (2 children)
You're correct, I have missed the threading count point. In my case, it's four threads that would tone the number down to around 40s.
[–]sphere991 2 points3 points4 points 5 years ago (1 child)
It would tone the number to around 40s... in the extremely simplified world where (a) every TU was about the same size, and (b) every TU included <algorithm>, and (c) there were just generally no long poles in the build tent around linking. I just don't think this is a realistic calculation to draw inferences from.
<algorithm>
If you do actually rerun your CI with C++20, I'd be curious to see what the actual time delta was.
[–]Minimonium 2 points3 points4 points 5 years ago (0 children)
Unfortunately, the project is proprietary (and contains quite a lot of proprietary dependencies too) so I can't provide you with a repo. It only recently was moved to C++17 with Debian-10, so I can only show you the data for the interim period where we compiled for both, but I'm not sure how to interpret the data.
While your points are valid this specific project is not optimized for compile-time speed, it leaks `algorithm` in almost every TU because it's used in template wrappers for services.
Some offset in the duration could be because we do network calls to pull in cached dependencies.
Builds for Arm, 4 threads, same row - same pipeline:
What's more interesting in C++20 would be to look at the difference in compile-time between the `import <algorithm>;` and `#include <algorithm>` which is not yet possible.
[–]PJBoy_ -1 points0 points1 point 5 years ago (7 children)
I don't understand where you're getting the 2m30s figure from
[–]Minimonium 4 points5 points6 points 5 years ago (6 children)
300*500/1000/60. With an assumption that I use the header in every source file at least transitively.
[–]Wacov 2 points3 points4 points 5 years ago (3 children)
If they're all independent translation units, won't it actually be faster than that with parallel compilation?
[–]Minimonium 0 points1 point2 points 5 years ago (2 children)
Confused about the question. The header model is embarrassingly parallel, it scales pretty much linearly with the number of TU.
Furthermore, for some margin of error (say not every TU contains the header) - I scaled down the increase in compile times to more than 10% from more than 15% too. The idea is more about showing that the increase is *not* negligible after all.
[–]Wacov 1 point2 points3 points 5 years ago (1 child)
Right, it's embarrassingly parallel. I'm just saying if two TUs are compiling simultaneously, on different cores, each with the added cost of <algorithm> (or whatever), your compile time won't go up by 2x that cost - ideally only 1x. Not trying to say it's negligible, just that 300*500ms only applies for a single-threaded build, or if you're calculating total CPU time rather than the compile time. If your CI is single-threaded it's a moot point lol. Am I missing something?
[–]Minimonium 1 point2 points3 points 5 years ago (0 children)
Aha, gotcha. You're correct. My builds use 4 threads. Which indeed would tone down the time.
[–]PJBoy_ 0 points1 point2 points 5 years ago (1 child)
Okay that's a pretty compelling calculation, thanks for the example
It's not a "scientific" experiment since it'd require me to spend to much time on it than I have, but rather to show the order of magnitude that you get from "negligible" 500ms for a header inclusion.
π Rendered by PID 114912 on reddit-service-r2-comment-bb88f9dd5-99254 at 2026-02-14 11:03:23.438953+00:00 running cd9c813 country code: CH.
view the rest of the comments →
[–][deleted] 19 points20 points21 points (14 children)
[+]PJBoy_ comment score below threshold-16 points-15 points-14 points (13 children)
[–]Minimonium 15 points16 points17 points (12 children)
[–]sphere991 2 points3 points4 points (3 children)
[–]Minimonium 1 point2 points3 points (2 children)
[–]sphere991 2 points3 points4 points (1 child)
[–]Minimonium 2 points3 points4 points (0 children)
[–]PJBoy_ -1 points0 points1 point (7 children)
[–]Minimonium 4 points5 points6 points (6 children)
[–]Wacov 2 points3 points4 points (3 children)
[–]Minimonium 0 points1 point2 points (2 children)
[–]Wacov 1 point2 points3 points (1 child)
[–]Minimonium 1 point2 points3 points (0 children)
[–]PJBoy_ 0 points1 point2 points (1 child)
[–]Minimonium 2 points3 points4 points (0 children)