[webkit-dev] std::optional: * or value()?

Jean-Yves Avenard jean-yves.avenard at apple.com
Mon Nov 25 02:16:22 PST 2024


I personally try to always use std::optional<T> the same as T*


To get access to a method of the inner object: 
 <https://en.cppreference.com/w/cpp/utility/optional/operator*>
operator-> <https://en.cppreference.com/w/cpp/utility/optional/operator*>
So to get the content : 
 <https://en.cppreference.com/w/cpp/utility/optional/operator*> <https://en.cppreference.com/w/cpp/utility/optional/operator*> <https://en.cppreference.com/w/cpp/utility/optional/operator*> <https://en.cppreference.com/w/cpp/utility/optional/operator*>operator* 

And to test if it contains a value `operator bool`

This is also consistent with Expected<T, F> , unique_ptr, RefPtr etc.

So I agree with you, to me, it makes it more concise and readable. I’d be happy if that went into the coding style.

> On 25 Nov 2024, at 9:03 pm, Anne van Kesteren via webkit-dev <webkit-dev at lists.webkit.org> wrote:
> 
> https://commits.webkit.org/238290@main seemed to express a preference
> for using * over value(), but the Code Style Guidelines are silent on
> this. Is this something we can establish a guideline for?
> 
> I personally think * makes the code slightly more readable due to it
> being more concise.
> _______________________________________________
> webkit-dev mailing list
> webkit-dev at lists.webkit.org
> https://lists.webkit.org/mailman/listinfo/webkit-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20241125/1ee65c4d/attachment.htm>


More information about the webkit-dev mailing list