This is an archive of the discontinued LLVM Phabricator instance.

Add getValueOr to llvm::Optional<T>.
ClosedPublic

Authored by jordan_rose on Sep 26 2014, 11:50 AM.

Details

Reviewers
dblaikie
Summary

This takes a single argument convertible to T, and

  • if the Optional has a value, returns the existing value,
  • otherwise, constructs a T from the argument and returns that.

Inspired by std::experimental::optional from the "Library Fundamentals" C++ TS (API, spec)

Diff Detail

Event Timeline

jordan_rose retitled this revision from to Add getValueOr to llvm::Optional<T>..
jordan_rose updated this object.
jordan_rose edited the test plan for this revision. (Show Details)
jordan_rose added a reviewer: dblaikie.
jordan_rose added a subscriber: Unknown Object (MLST).
dblaikie edited edge metadata.Sep 26 2014, 11:51 AM

Could you link to the spec for std::experimental::optional somewhere?

What's the form of this operation in std::experimental::optional? Should we move towards matching that interface more precisely so we can one day remove our custom implementation?

jordan_rose edited edge metadata.

Link added in description and here: API, spec.

std::experimental::optional has the same signature but calls this operation value_or. We also have getValue (value in the TS), and getPointer and hasValue (no TS equivalent). I think I'd rather match what we're doing now, and switch everything together if we get to that point.

dblaikie accepted this revision.Sep 26 2014, 12:41 PM
dblaikie edited edge metadata.

Looks good

This revision is now accepted and ready to land.Sep 26 2014, 12:41 PM
jordan_rose closed this revision.Sep 29 2014, 12:06 PM

Committed as r218618.