7 ms·
Ask HN: Name good examples of Modern C++ usage
Hi folks,
I'm basically looking into making the transition from a C++98 world into what is supposed to be Modern C++.
Since that is a rather opinionated field I'd love to see a few real world examples. Shoot links to your favourite Open Source project :-)
- marenkay 9y agoLadies and gents, thanks a lot; those are some nice starting points!
- cottonseed 9y agoTwo previous Reddit threads on this topic: https://www.reddit.com/r/cpp/comments/489f9l/open_source_projects_with_examples_of_good_modern/ https://www.reddit.com/r/cpp/comments/489f9l/open_source_pro... https://www.reddit.com/r/cpp/comments/5sxrun/what_are_some_examples_of_new_modern_c_projects/ https://www.reddit.com/r/cpp/comments/5sxrun/what_are_some_e... My list: SeaStar and ScyllaDB https://github.com/scylladb/seastar https://github.com/scylladb/seastar https://github.com/scylladb/scylla https://github.com/scylladb/scylla Cap'n Proto https://github.com/sandstorm-io/capnproto https://github.com/sandstorm-io/capnproto LLVM range-v3 https://github.com/ericniebler/range-v3 https://github.com/ericniebler/range-v3 Facebook folly https://github.com/facebook/folly https://github.com/facebook/folly easylambda https://github.com/haptork/easylambda https://github.com/haptork/easylambda thrust https://github.com/thrust/thrust https://github.com/thrust/thrust xtensor https://xtensor.readthedocs.io/en/latest/numpy.html https://xtensor.readthedocs.io/en/latest/numpy.html
- desdiv 9y agohttps://github.com/dolphin-emu/dolphin https://github.com/dolphin-emu/dolphin
- jchw 9y agoha. As a former contributor to dolphin-emu (very minor though, too busy :() I'd caution against calling it a "good example of Modern C++." It's an amazing program written by super smart people, but some of the things that lurk in there can be quite messy. Of course, I'm sure it has improved markedly since the Google Code days, but still... That being said, on the other hand, there ARE some nice usages of modern C++ in certain parts. I also like their choice to move to #pragma once - I know it's non-standard but despite pretty intense arguments it seems to do the job just fine.
- lwansbrough 9y agoI'm not a C++ developer by trade (mostly C#) but this looked compelling when I was looking to create high performance Windows app middleware: https://github.com/microsoft/cppwinrt https://github.com/microsoft/cppwinrt
- jjuhl 9y agoI would name Eric Nieblers range-v3 library : https://github.com/ericniebler/range-v3 https://github.com/ericniebler/range-v3 - amazing stuff.
- jchw 9y agoSince Dolphin-emu came up, in the realm of emulators I have to mention byuu's Higan emulator. It's got some really cool stuff going on, though the perfectionism is a bit intense (it has its own STL-replacement!) YMMV for some of the decisions, but seriously, there's a lot of great stuff. I always cite the ARM instruction decoder as being my favorite part, but there's really a lot of great use of cutting edge C++ all over the place. Byuu seems to adopt C++ features roughly as soon as GCC and Clang support them, or maybe sooner... If you want something a bit more orthodox, or perhaps less depending on how you look at it, on the other end of the spectrum is the intensely engineered "Boost" libraries. Though, to be honest, that may be pushing it as far as "modern C++" goes considering it's written to support older C++98 compilers in many instances. Qt 5 is one of my all-time favorite C++ projects, although it's again worth noting that it may be pushing it to consider it modern C++. I believe they're currently on C++11 with Qt, so a bit further than C++98. Still... there's plenty to learn about even older C++. There's more out there, but those are the ones that come to mind for me. I have been out of the C++ game for a while now.
- jchw 9y agoOh yeah, one last thing: not an example, but a pretty useful reference- Google's C++ Style Guide. https://google.github.io/styleguide/cppguide.html https://google.github.io/styleguide/cppguide.html I've not read the whole thing, but it looks pretty solid. Of course, there's a lot of highly subjective suggestions, but I can get behind many of them personally.
- gumby 9y agoNote that the style guide contains recommendations specific to Google's situation (they note this in the guide). For example they recommend against exceptions because by the time the style guide was written they already had an installed base. Had they started over they would use them. Having recently started a project from "empty buffer" state we elected to go with C++17 (supported now in both GCC and clang although with some library features still missing). It's worked out well for us, but in my case I approached it as a brand new language rather than an evolution of old C++ (which I'd started in the cfront days and dropped around 2000). In that light it became and expressive and powerful systems programming language that is fun to use.
- agauniyal 9y agoCan I post mine :) Here is a short but useful terminfo parsing library I wrote - https://github.com/agauniyal/termdb https://github.com/agauniyal/termdb And here is another for console decorations - https://github.com/agauniyal/rang https://github.com/agauniyal/rang Recently I worked on a network programming library (still WIP) for college project - https://github.com/c10k/net/tree/develop https://github.com/c10k/net/tree/develop And here is a boilerplate to get you all started with Continuous Integration, Unit tests etc etc - https://github.com/agauniyal/cppb https://github.com/agauniyal/cppb I try to write good code everywhere but since I lack experience so the code might not be perfect. Hence I advise to go light on it. Have a good day :)
- rahkiin 9y agoLLVM is my favorite C++ project. (Together with clang and swift)
- mhh__ 9y agoLLVM is a very interesting project when it comes to C++ style. It is very much modern C++, except that they implement quite a lot of stuff themselves (e.g. RTTI and dynamic_cast/dyn_cast). Certainly very well engineered, but I wonder whether some of the techniques are strictly necessary (It works well, so I'm not complaining)
- atemerev 9y agoDoesn't contain many "modern" features, but nevertheless, probably the best C++ code I ever saw, and it is usually hard for me to give any praise for C++. Stockfish chess engine (currently 1st place by Elo). I am really impressed: https://github.com/official-stockfish https://github.com/official-stockfish
- nick0garvey 9y agohttps://github.com/facebook/folly https://github.com/facebook/folly
- fishnchips 9y ago+1 to Folly for elegant modern code, but their use of shared pointers is nothing to be proud of, at least in the C++ world.
- Frogolocalypse 9y agoI've yet to find a valid use for a shared_ptr. A unique_ptr is great to use for polymorphism but I've always thought if you can't figure out what owns what in memory in a program, you haven't planned it very well.
- pjmlp 9y agoThen I imagine you never had the fun of feature driven software development by consultants at enterprise level. Being one, this works like this. Company X, which main business has 0% to do with software development requires a new feature on an application being used at deparment Y. They send out an RFP to several consulting companies, the one that gets the gig, sends a few developers, which get a configured devenv from company X IT department and implemente the requested features and go away. Manual memory management languages became out of fashion in such kind of companies, because it is almost impossible to jump into a gigantic ball of mud, while keeping track of all ownerships.
- Frogolocalypse 9y agoI understand that you have legacy requirements to support elements that previous developers have used, but that doesn't explain why someone would use a shared_ptr in the first place. The great thing about unique_ptrs is that they take away the manual memory management. It is a complete PITA not having them. I can even see the use in weak_ptrs. My issue is with shared. I can't see how their use wouldn't lead to larger problems in code.
- nly 9y agoHere's an existing compilation of such work: https://github.com/rigtorp/awesome-modern-cpp https://github.com/rigtorp/awesome-modern-cpp A couple of my personal favourite libraries that I consider modern: The Parsing Expression Grammar Template Library - https://github.com/taocpp/PEGTL https://github.com/taocpp/PEGTL Beast: HTTP and WebSockets in C++11 - https://github.com/vinniefalco/Beast https://github.com/vinniefalco/Beast
- kodisha 9y agoDoom 3 BFG on github https://github.com/id-Software/DOOM-3-BFG/blob/master/README.txt https://github.com/id-Software/DOOM-3-BFG/blob/master/README...
- johnbellone 9y agoI suppose that depends on your definition of modern! The id Tech 4 engine is over a decade old, and like most game engines uses their own data structures. Many additionals to the C++ standard have been in the standard libraries.
- Narishma 9y agoThat's very far from Modern C++. It's more the C with classes style of C++.
- tjalfi 9y agoKenny Kerr's dx.h library[0]. He has also written several articles[1][2] that discuss the design of its unique_handle class. [0] https://dx.codeplex.com/ https://dx.codeplex.com/ [1] https://msdn.microsoft.com/en-us/magazine/hh288076.aspx https://msdn.microsoft.com/en-us/magazine/hh288076.aspx [2] https://visualstudiomagazine.com/articles/2013/09/01/get-a-handle-on-the-windows-api.aspx https://visualstudiomagazine.com/articles/2013/09/01/get-a-h... Edited to fix footnote formatting
- andreasgonewild 9y agoSnackis may be considered more post-modern than modern, I prefer open structs and free functions to classes and methods and simple/custom to over-engineered; but it depends on plenty of new C++-features to do its magic: https://github.com/andreas-gone-wild/snackis https://github.com/andreas-gone-wild/snackis
- mabynogy 9y ago- variadic template arg (static va_start/end) - rvalue&& (avoid few copies) - enum class (enum with a size and a namespace)
- duarten 9y agoSeastar (https://github.com/scylladb/seastar https://github.com/scylladb/seastar) and Scylla (https://github.com/scylladb/scylla https://github.com/scylladb/scylla).
- tcbawo 9y agoI've been impressed by the Sea star Project (http://www.seastar-project.org/ http://www.seastar-project.org/). It was developed to build a high throughput database (ScyllaDB) but has since been used in several other projects. I recently spent some time evaluating it as a starting point for a new application. Also, a fan of the elegance on display is this serialization library: https://github.com/msgpack/msgpack-c https://github.com/msgpack/msgpack-c
- pacala 9y agohttps://github.com/google/leveldb https://github.com/google/leveldb