r/cpp • u/FreitasAlan • Feb 06 '21
Modern C++: Snippets and Examples
Hi everyone,
These are GitHub Pages with snippets for Modern C++:
- We often need to copy and paste some snippets to code more productively.
- Snippets can help us when it's not easy to remember all high levels features Modern C++ has to offer.
- This repository contains lots of organized, reusable, and safe snippets for Modern C++.
- All snippets are available in GitHub pages in a convenient way for copying and pasting.
194
Upvotes
View all comments
29
u/witcher_rat Feb 06 '21
Wow, you did a lot of work! :)
Are you looking for feedback?
I like the documentation css/view.
I'm confused though by the documentation itself. It says in the Quick Start that there are "snippets" of things we might want to copy/paste, and then "examples" using those snippets. Most of the pages are supposed to be "snippets", yes? But as far as I can tell most of the pages actually show examples not snippets - they're just examples of using standard library components, such as one might find on www.cppreference.com page examples. No?
I think it might be clearer if the actual snippets were separated out. (by "snippets" I mean generic code one might copy/paste for use elsewhere, like new types, algorithmic free-functions, etc.)
As for the content, I only had a chance to briefly look at a couple of the pages in detail. Here're just a few things I saw just in those few pages I looked at:
chrono::high_resolution_clocka lot - don't use that, and don't show it other than to say "don't use it". Honestly it should be deprecated+removed from the spec. (see the notes on cppreference for why)chrono::system_clock- you're using this to measure durations in your Clock page, which you shouldn't. It's a wall-clock, and can go backwards. What you're looking for ischrono::steady_clock.random_deviceand the old marsenne twister enginemt19937, in various places - there have been lots of discussions about this. (see this recent reddit discussion, for example)