Live data from Hacker News

C++20 Reference Card

bfilipek.com

1–10 of 48 posts

Re: C++20 Reference Card

#2
> 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 
[1] https://en.cppreference.com/w/cpp/ranges/iota_view

Re: C++20 Reference Card

#3
Do 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/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.

Re: C++20 Reference Card

#5
post #4

Could someone please explain why you'd put nodiscard on a constructor? I'm a bit confused as to when that's needed.

If 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.

Re: C++20 Reference Card

#6
post #5
post #4

Could someone please explain why you'd put nodiscard on a constructor? I'm a bit confused as to when that's needed.

If 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.

So it's for copy/move-constructors only?

Re: C++20 Reference Card

#8
post #3

Do 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/functio... If you know a coupl…

Not sure about printed per se, but would definitely appreciate a modern concise Swift reference!

Re: C++20 Reference Card

#10
post #6
post #5

Earlier quoted context omitted.

If 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.

So it's for copy/move-constructors only?

No. 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(m_mutex);
        do_the_mutation();
    }
"unique_lock(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

[2] http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p177...

Post reply on HN