3 ms·
Again, I'm not arguing that operator* should check for nullness, I'm arguing that it shouldn't exist. With `kj::Maybe` and `KJ_IF_MAYBE`, using the syntax I de
by kentonv 6y ago
Again, I'm not arguing that operator* should check for nullness, I'm arguing that it shouldn't exist.
With `kj::Maybe` and `KJ_IF_MAYBE`, using the syntax I demonstrated above, you check for nullness once and as a result of the check you get a direct pointer to the underlying value (if it is non-null), which you then use for subsequent access, so you don't end up repeating the check. So, you get the best of both worlds.
> it's likely ~30 loc to wrap std::optional
It's even easier to replace std::optional rather than wrap it. The value of std::optional is that it's a standard that one would hope would be used across libraries. But because it's flawed, people like me end up writing their own instead.
- jcelerier 6y ago> So, you get the best of both worlds. I would really not call code that looks like this "best of both worlds" KJ_IF_MAYBE(value, maybeValue) { use(value); } else { handleNull(); } when compared to if(!value) handleNull(); use(*value);
- kentonv 6y agoKind of unfair that you didn't include the `else` or the braces in your version, just to make it look shorter.