Add HPHP::Optional
Summary:
folly::Optional has the undesirable property that attempting to access
the optional when it is disengaged will throw an exception. This makes
such bugs difficult to diagnose, since the exception unwinds the
stack. In theory we could catch the exception and try to recover from
it, but such behavior is always a bug.
We could use std::optional instead, but that simply defines such an
access as undefined behavior (current implementation seems to do no
checks). So, that's hardly better.
Instead provide a drop in replacement for std::optional called
HPHP::Optional. This has (almost) the exact interface of
std::optional, but accessing value when disengaged will always
assert. Going forward, this is meant to be used instead of
std::optional or folly::Optional.
The implementation just wraps a std::optional, but inserts the
necessary checks.
Reviewed By: mofarrell
Differential Revision:
D29291162
fbshipit-source-id:
ab8dc39cd967fafe9cefe633af078c99c67fc9dd