AK: Variant the union thing [2/N] - #26916
Open
Hendiadyoin1 wants to merge 4 commits into
Open
Conversation
Hendiadyoin1
marked this pull request as draft
August 1, 2026 10:45
|
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions! |
Hendiadyoin1
force-pushed
the
variant-p2
branch
from
August 23, 2026 12:22
32aad1c to
0a08c97
Compare
Hendiadyoin1
marked this pull request as ready for review
August 23, 2026 12:23
Hendiadyoin1
force-pushed
the
variant-p2
branch
9 times, most recently
from
August 28, 2026 09:39
efb8776 to
ede427e
Compare
This makes the overload resolution logic a lot cleaner. If we have needs for duplicate types we can rely on `DedupAndApply` to strip duplicate types before they reach Variant proper.
For constructing the Storage we use a sentinel value (`VariantIndex`) to pass along the desired depth/type into the constructor chain. This is done as we cant easily start the lifetime of the alternatives after the union was instantiated. Upcoming c++26 features should fix this (see trivial unions (P3074R7) and std::start_lifetime (P3726R2)) For move and copy assignment we destroy the active member, and then replace the whole storage, trivial unions may also make this nicer. Also Overload resolution now returns the chosen overload wrapper, which now also holds the index of that overload, which avoids re-walking the type list to get the index.
Hendiadyoin1
force-pushed
the
variant-p2
branch
from
August 29, 2026 13:18
ede427e to
0ddd90d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This does two things:
This allows stripping some extra logic from the overload resolution and makes the next step easier
On clang this might also be a bit nicer on the compiler