dpiponi, 1 month ago 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.
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.
demofox, 1 month ago @dpiponi and good language / library design makes you not have to worry about so many of those little details that don't matter towards doing what you are trying to do.
@dpiponi and good language / library design makes you not have to worry about so many of those little details that don't matter towards doing what you are trying to do.
demofox, 1 month ago @dpiponi I just mean to say, you aren't the one that should be embarrassed about that 😀
@dpiponi I just mean to say, you aren't the one that should be embarrassed about that 😀
Add comment