Earlier quoted context omitted.
Off topic. Could you recommend an ide to work with c++?
CLion from JetBrains and Microsoft Visual Code are the best commercial ones for Linux, NetBeans is a free (as in freedeom and open source) one (that also supports many other languages like Java and Python). What I don't recommend is Eclipse - it's complex and confusing for beginners (but a bit faster than some others).
C++ Cheat Sheets
11–20 of 82 posts
Re: C++ Cheat Sheets
#12Earlier quoted context omitted.
* Compile with clang, link with mold or at least lld. mold can link gigabyte-sized binaries in, like, one second * Use ninja instead of make * Use PCH * -gsplit-dwarf
Off topic. Could you recommend an ide to work with c++?
Re: C++ Cheat Sheets
#13Earlier quoted context omitted.
* Compile with clang, link with mold or at least lld. mold can link gigabyte-sized binaries in, like, one second * Use ninja instead of make * Use PCH * -gsplit-dwarf
Off topic. Could you recommend an ide to work with c++?
Re: C++ Cheat Sheets
#14Wow, this is really good, there are still things I can learn. C++ really has a lot of good things. It's just a shame it's so slow to compile. I'm curious if anybody is working to make C++ faster to compile. Even if it was a subset of the language, with some features removed, it would be good enough for me.
* Compile with clang, link with mold or at least lld. mold can link gigabyte-sized binaries in, like, one second * Use ninja instead of make * Use PCH * -gsplit-dwarf
IME, the single best way to reduce your C++ compile times is to compile less code:
* Remove all unnecessary headers. Template expansion is slow, and preprocessing is even slower. Some of the standard includes (like `` and ``) are notorious for slowing individual translation units to a crawl. `#pragma once` for your own headers also helps with cpp-time performance.
* Forward-declare as much as you can. Forward type declarations mean that the compiler doesn't need to process all of `Foo` when it sees `Foo&` or `Foo`.
Use pImpl wherever you can (and makes sense). Private implementations similarly reduce the amount of code the compiler needs to analyze.
For better or worse, the current winds suggest that C++ compilation times will only continue to get worse (more constexpr/consteval, even more complex templating features/concepts, etc.).
Re: C++ Cheat Sheets
#15Re: C++ Cheat Sheets
#16In a similar vein: I've had the "initialization in C++17" chart taped above my desk for a 3 years now[1]. [1]: https://timur.audio/initialisation-in-c17-the-matrix
Re: C++ Cheat Sheets
#17Re: C++ Cheat Sheets
#18Earlier quoted context omitted.
* Compile with clang, link with mold or at least lld. mold can link gigabyte-sized binaries in, like, one second * Use ninja instead of make * Use PCH * -gsplit-dwarf
Off topic. Could you recommend an ide to work with c++?
Re: C++ Cheat Sheets
#19Earlier quoted context omitted.
* Compile with clang, link with mold or at least lld. mold can link gigabyte-sized binaries in, like, one second * Use ninja instead of make * Use PCH * -gsplit-dwarf
This is all solid advice (particularly using a faster linker). IME, the single best way to reduce your C++ compile times is to compile less code : * Remove all unnecessary headers. Template expansion is slow, and preprocessing is even slower. Some of the standard includes (like ` ` and ` `) are notorious for slowing individual translation units to a crawl. `#pragma once` for your own headers also helps with cpp-time…
> * Forward-declare as much as you can. Forward type declarations mean that the compiler doesn't need to process all of `Foo` when it sees `Foo&` or `Foo`.
I've found the include-what-you-use (IWYU) tool [1][2] can help immensely with automating this process, especially on large code-bases.
It uses LLVM/Clang to analyze a .cpp file / translation unit and produces the minimal subset of exactly which includes are necessary and what types can be forward declared.
[1] https://include-what-you-use.org/
[2] https://github.com/include-what-you-use/include-what-you-use
Re: C++ Cheat Sheets
#20The supplied C++ docset comes from cppreference.com and is very, very useful to have to hand.
The Python and CMake docsets are also particularly useful to me.