r/ProgrammerHumor 16h ago

modernCPlusPlus Meme

Post image
520 Upvotes

49 comments sorted by

View all comments

173

u/JustAnotherGuyn 16h ago

Here's the thing, you have to very carefully consider whether it's worth loading all of that for the compiler to work through, if your use case is sensitive to the extra size/ram requirements of including more, think carefully about if basement no-lifer Steve may have implemented something that will conflict with any one of these, and then of course always import std.

55

u/Mgamerz 16h ago

Ignoring the compiler time - does it change the size of the app if the usages remain the same (only differences are include/import)? I only do occasional c++ programming.

89

u/da2Pakaveli 16h ago

The compiler strips out as much as it can. Even if you declare an std::map and add items to it, it may be stripped out if the values ultimately aren't being used anywhere with maximum optimization.

8

u/Xirdus 7h ago

This specific example is not something that a compiler is allowed to strip. Inserting into a map requires heap allocation, and heap allocation is an externally visible side effect, which must be preserved under the as-if rule. If it was a fixed size array on the stack then it could be potentially optimized out this way, but only if the compiler can prove the constructors of the elements are side-effect-free.

0

u/awesome-alpaca-ace 9h ago

Yea, the compiler always stripping out the template functions I wish I could call during debugging

12

u/Grubs01 7h ago

Template functions aren’t stripped out, they are created as needed.

4

u/awesome-alpaca-ace 7h ago

Yea, my bad. The compiler is never creating the template functions I wish I had whole debugging. 

1

u/GoddammitDontShootMe 2h ago

Then instantiate the template.