HACKER Q&A
📣 mettamage

C++17/C++20 example projects with good style?


Hi HN!

I'm reading A tour of C++ (for the second time). I'm also busy working on my application. What I'm noticing is that I have no clue about code style, build systems or anything else outside of that book. If I don't know about it, you can bet that it is hacked together.

I'm mentioning both C++ versions because I've noticed that C++20 features aren't complete, and some features are not well received either (e.g. modules). So I'm doubting if I should learn C++20 for now.

So do you know of any good example projects that show some good stylistic sense C++17/C++20? And I know that people code differently, but trust me, they aren't coding it like I am right now (e.g. .cpp files only, a hacked together build with Meson and benchmark code that have 10ms of test setup bias -- I just discovered that).


  👤 emgo Accepted Answer ✓
I've always found the Google C++ Style Guide useful, although it's about C++ in general and not specifically C++17 or C++20 (https://google.github.io/styleguide/cppguide.html). Sure it's specific to Google's need, but a lot combined experience went into it, and shouldn't be ignored.

There's also an interesting talk from CppCon 2014 where Titus Winter explains how they came up with it: https://www.youtube.com/watch?v=NOCElcMcFik

Here is something a bit similar from the Chromium team: https://chromium-cpp.appspot.com/

As for good projects written in C++, some of which is modern C++, I've always found LevelDB and Chromium to be good starting points. Here is a list of more projects which may help you: https://awesomeopensource.com/projects/modern-cpp

Finally, on your mention of "So I'm doubting if I should learn C++20 for now" => if you're in doubt, then 99% of the time the answer is no, don't spend time on it.

Learning has a diminishing return, especially once you reach the point of over-learning and spend time learning things you don't need or will never use. It's a lost opportunity as you could have spent that time learning something else that would actually be useful to you.

Wait until something either (1) become widely used and you can't ignore it, or (2) is required for you to get the job done -- because then you know it's actually useful for you to spend the time learning it.

I hope this helped, good luck with your learning!


👤 radiantxp21
Not an example project, but it might help to get a grasp of good style: https://www.reddit.com/r/cpp/comments/le52s3/modern_c_snippe...

The C++ subreddit is an interesting place in itself :)


👤 mettamage
Some fun things I've figured out:

* https://github.com/fastfloat/fast_float <-- for fast float/double conversion

* from_chars() for fast integer conversion (though I benchmarked a few that were slightly faster but probably less robust), see https://en.cppreference.com/w/cpp/utility/from_chars

* https://github.com/simdjson/simdjson <-- apparently the fastest JSON library

It's hard to program normal anymore, for every little thing I ask myself "but I want it faster!" TypeScript was so much easier, other than O(n) and friends, I never cared xD


👤 mettamage
A couple of things I learned thus far, not projects, but helpful to note down somewhere:

* Meson is a nice build system, I never felt I was really fighting it

* Catch2 is pretty nice for unit testing

* VSCode has a nice integrated debugger that runs on gdb (Linux).

* The C++ back to basics YouTube series was helpful, it taught me that C++17/C++14 has some nice syntactic sugar for things you couldn't do in C++11.

* Simd instructions are hip for faster computation. Though, I also have to refresh my memory on writing CPU cache friendly code.

* Pragma #once in header files is uch easier than the more portable define guards, and I'm targeting Clang/GCC anyway

* The bureaucracy of C++ is felt when writing header files and handtyping files in your Meson build file, ah well.

* Cppreference is my bible.


👤 Sheeplator
A list of modern C++ related resources can be found here:

https://github.com/rigtorp/awesome-modern-cpp

The list includes some powerful yet not excessively large libraries from which one can learn including:

https://github.com/skypjack/entt

https://github.com/taocpp/PEGTL

https://github.com/fmtlib/fmt


👤 mettamage
For now, I found this [1]. I wonder if anyone on HN knows a project or two ;-)

[1] https://github.com/fffaraz/awesome-cpp