-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AK/Optional: Make some member functions constexpr #24978
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally don't like the hoops the standard makes us jump through, but that's not a blocking issue
Great change anyway, did you notice any changes in codesize or the like?
This PR currently breaks at Userland/Applications/PixelPaint/Tools/MoveTool.cpp:63 because there's an assignment to an Optional<const ....>. But so would std::optional: https://godbolt.org/z/z8c68e94Y |
Thaat looks like a logic bug, feel free to fix it |
squashed the 'fixup' commits |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I generally like the idea, thanks! Please see the review comment.
Also, please add a test to ensure this is actually usable in a constexpr
/consteval
context.
802df7a
to
d5961c5
Compare
construct_at has to be defined in the std namespace because outside of it, compilers wouldn't allow it to be constexpr because of its use of placement new.
This will allow Optional's Ctors to be constexpr. Switching Optional's m_storage to be a union member is necessary if we want to avoid pointer conversions, which we won't be allowed to do when those functions are constexpr.
With films work on Optional<T&>, this now has conficts |
This PR changes some of Optional's member functions to be constexpr - for now only the non-reference variant. Notably, this requires using construct_at instead of placement new to create the contained object and storing it in a union instead of a byte buffer.