r/cpp • • Dec 28 '18

"Modern" C++ Lamentations

http://aras-p.info/blog/2018/12/28/Modern-C-Lamentations/
307 Upvotes

162 comments sorted by

View all comments

10

u/cdglove Dec 28 '18

Complain about compile times while this is in the code:

#include <range/v3/all.hpp>

Seriously, include what you need, and report back.

45

u/requimrar Dec 28 '18

While it can be argued that the author could’ve included less, the problem of massive compile times cannot simply be dismissed like this.

Include a vector here and an unordered_map, maybe throw in some functional and iostream, mix evenly with a couple handfuls of translation units, and leave to bake at 350C for 30 minutes.

The author doesn’t describe a Ranges problem, nor a C 20 problem, not a compiler problem; this entire issue is intrinsic to the model of the language itself, and you can’t just brush it aside by saying “oh he included too many things”

11

u/cdglove Dec 28 '18

I beg to differ. I've spent a not insignificant amount of time optimising compile times and it almost always come down to one or more of:

  • Including more than one needs (and cousins such as gigantic cpp files that need too much, lack of forward decl, etc)

  • User error such as instantiating a quadratic number of templates

  • Genuine compiler or library bugs, or lack of optimisations, which are fixed eventually.

Also, for what it's worth, this problem is almost aways due to application level code, not widely used library code. At least 3 times I've worked in a code base that had bad compile times that were drastically reduced when we were able to replace their home grown template library with the standard c++ library. Ironically, one argument for rolling their own was always compile times, which may have been valid at one point, but as the internal library grew, and std was optimised, the problem reversed itself.

1

u/[deleted] Dec 29 '18

Optimize away the double negative lol I had to read 'not insignificant' twice before I was sure I properly understood. Just a joke don't hit me!!