This is an archive of the discontinued LLVM Phabricator instance.

[ADT] Implement Optional::transform
ClosedPublic

Authored by kazu on Aug 12 2022, 11:00 PM.

Details

Summary

This patch implements Optional::transform for consistency with
std::optional::transform in C++23.

Note that the new function is identical to Optional::map. My plan is
to deprecate Optional::map after migrating all of its uses to
Optional::transform.

Diff Detail

Event Timeline

kazu created this revision.Aug 12 2022, 11:00 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 12 2022, 11:00 PM
kazu requested review of this revision.Aug 12 2022, 11:00 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 12 2022, 11:00 PM
dblaikie accepted this revision.Aug 13 2022, 11:14 AM

Sounds good - in the abstract it'd bee good not to duplicate the code or testing (old testing could be minimized if old implementation were rewritten as a wrapper around the new implementation) - but it's perhaps not enough to matter (hardly likely to have much in the way of bug fixes/changes to the testing or implementation that could diverge) and will make it simpler/easier to remove the old one later - so whatever works best for you.

This revision is now accepted and ready to land.Aug 13 2022, 11:14 AM
kazu added a comment.Aug 13 2022, 11:40 AM

Sounds good - in the abstract it'd bee good not to duplicate the code or testing (old testing could be minimized if old implementation were rewritten as a wrapper around the new implementation) - but it's perhaps not enough to matter (hardly likely to have much in the way of bug fixes/changes to the testing or implementation that could diverge) and will make it simpler/easier to remove the old one later - so whatever works best for you.

Thanks for the review! I wasn't sure I could safely turn map into a wrapper while preserving all the move semantics, the number of &, etc, so I just copied the code. :-P

We don't have a test for map, so adding a test for transform should be a pure improvement.

This revision was landed with ongoing or failed builds.Aug 13 2022, 11:48 AM
This revision was automatically updated to reflect the committed changes.