[webkit-reviews] review granted: [Bug 234865] Add a helper function that returns the value of a std::optional<T> or constructs T if needed : [Attachment 448467] Patch

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Thu Jan 6 09:29:49 PST 2022


Darin Adler <darin at apple.com> has granted Wenson Hsieh
<wenson_hsieh at apple.com>'s request for review:
Bug 234865: Add a helper function that returns the value of a std::optional<T>
or constructs T if needed
https://bugs.webkit.org/show_bug.cgi?id=234865

Attachment 448467: Patch

https://bugs.webkit.org/attachment.cgi?id=448467&action=review




--- Comment #6 from Darin Adler <darin at apple.com> ---
Comment on attachment 448467
  --> https://bugs.webkit.org/attachment.cgi?id=448467
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=448467&action=review

> Source/WTF/wtf/StdLibExtras.h:601
> +    return std::forward<OptionalType>(optional).value_or(typename
std::remove_reference_t<OptionalType>::value_type { });

It would be even better to make this more generic to work with optional-like
things that are not std::optional. I like the idea of one that is based on null
checking and the dereferencing operator rather than on value_or and value_type:

    if (optional)
	return std::forward<OptionalType>(optional);
    return decltype(*optional) { };

Not sure that code is exactly correct, but it’s the concept. But of course, we
can make this change *after* landing an initial version, because it should not
have any effect on std::optional call sites.


More information about the webkit-reviews mailing list