Why Nostr? What is Njump?
2024-05-08 01:15:30

Dan Piponi on Nostr: Let me tell you about my embarrassingly stupid C++ mistake so you don't have to make ...

Let me tell you about my embarrassingly stupid C++ mistake so you don't have to make it:

If X is of type std::optional<T> and Y is of type T you can assign Y to X like so:

X = Y

I sort of don't like that because X and Y are different types.

You can also write

*X = Y

which works because *X is of type T&. Now the types match.

But woe is me! Don't do the latter. If X is an empty optional then *X = Y fails silently.

It's obvious when you think about it for a moment. But when you're thinking about the bigger picture you can forget about the little things.
Author Public Key
npub1xs30e0pj7velktf5sxewnqf93tu2pdt3s6wtl6fug2tzgy8zxthsgfgrae