10 ms·
C++20 Reference Card
- wyldfire 7y ago> Range-based for with initialiser Gee, I would really love something like Python's enumerate() and zip() (but yes, I know that there's alternatives available that are not in the standard library). > std::format / Python-like formatting library in the Standard Library! Yes, this is a good addition. > Ranges / A radical change in how we work with collections! ... but I still have to use verbose warts like std::iota in order to make a collection of integers? EDIT: no, apparently not. Sanity prevails! (see [1]): for (int i : std::views::iota{1, 10}) std::cout << i << ' '; [1] https://en.cppreference.com/w/cpp/ranges/iota_view https://en.cppreference.com/w/cpp/ranges/iota_view
- melling 7y agoDo people like printed reference cards? I’m working on a Swift Cookbook. It started as web pages but I’ve moved it to Github. Considering doing an ePub or trying to cram a lot into a one pager. Having Strings, Sets, Arrays, Dictionaries, and Functional examples on one page might be useful, for example. Here are my functional examples: https://github.com/melling/SwiftCookBook/blob/master/functional.md https://github.com/melling/SwiftCookBook/blob/master/functio... If you know a couple languages, my thinking is that a few pages of examples should be enough to get started in another language.
- gregsadetsky 7y agoNot sure about printed per se, but would definitely appreciate a modern concise Swift reference!
- mehrdadn 7y agoCould someone please explain why you'd put nodiscard on a constructor? I'm a bit confused as to when that's needed.
- wyldfire 7y agoIf it's constructed as a temporary rvalue but never stored or passed as an argument, I think there's places where the compiler can elide the code entirely. Whereas you might prefer it have the system side effects associated with construction and destruction.
- mehrdadn 7y agoSo it's for copy/move-constructors only?
- wyldfire 7y agoNo. Sorry for being unclear. [1] is a great video that covers a lot of good stuff in particular this usability bug. It's worth watching in its entirety. If you don't want to sit through the video, here's the broken code in question: void Obj::update() noexcept { unique_lock<mutex>(m_mutex); do_the_mutation(); } "unique_lock<mutex>(m_mutex);" has no effect, but you might mistakenly think that this will block on m_mutex. Labeling unique_lock's constructor as [[nodiscard]] would force you to think twice. See [2] for more details. [1] https://youtu.be/lkgszkPnV8g?t=1767 https://youtu.be/lkgszkPnV8g?t=1767 [2] http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1771r0.pdf http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p177...
- mehrdadn 7y agoAhh, that makes sense! On my phone at the moment but will check out the video too, thanks!
- deleted 7y ago[deleted]
- thestoicattack 7y agoTo avoid this insidious bug: std::lock_guard<std::mutex>(m); // guard is immediately thrown away versus the correct std::lock_guard<std::mutex> g(m); // hold mutex til end of scope
- gregsadetsky 7y agoDirect links: C++20 Features https://mcusercontent.com/e93417593cbf4da3dba03d672/files/4263f191-6c76-43b6-b33b-984c34cdd737/cpp20_refcard_29th_jan.pdf https://mcusercontent.com/e93417593cbf4da3dba03d672/files/42... Language Features of C++17 https://gallery.mailchimp.com/e93417593cbf4da3dba03d672/files/ef3a6d15-7f2f-4f5f-8c11-90f2efd2f0e8/cpp17_language.pdf https://gallery.mailchimp.com/e93417593cbf4da3dba03d672/file...
- erichdongubler 7y agoThanks. I really don't want another newsletter in my email inbox!
- joebaf 7y ago[author here] you can always unsubscribe at any time, I think it's a fair trade. So please consider removing that comment with the links.
- pron 7y agoWhenever I see new C++ features I'm all the more impressed with how Zig manages to provide capabilities similar to -- and at least as powerful as -- type templates, value templates, constexprs, concepts, and conditional compilation (preprocessor), with a single feature and keyword, without any type/template-level programming, a preprocessor or AST macros (i.e. mini-languages different from the ordinary computation language that one has to learn and can make code quite opaque), all in a language that is about as simple as C and can be fully learned in a day or two.
- fiter 7y agoCould you give or point to some examples?
- pron 7y agohttps://kristoff.it/blog/what-is-zig-comptime/ https://kristoff.it/blog/what-is-zig-comptime/
- lostmsu 7y agoDamn it looks good. I wish it could target and consume .NET or Java.
- unwind 7y agoWhat does that even mean? "Target" I guess could mean that it could compile to code for those virtual machines? That would make some sense although for a language that sets out to compete with/replace C it would be a bit strange. For "consume" I don't know ... do you mean "call into", or something?
- lostmsu 7y agoCorrect on both cases. With .NET I'd love integration with existing types and generics too. Actually, I was just thinking aloud. I don't really mean for Zig authors to target .NET, but rather have .NET Core runtime and C# to have the concept of compile-time values and types.
- asdfasgasdgasdg 7y agoAll this stuff actually made it in!? Concepts look great! Love ranges too.
- forgotpwd16 7y agoThere is nothing that cannot make it in C++.
- deleted 7y ago[deleted]