Adds a method getAsOr to Optional, This functions somewhat like getValueOr however it casts the value to a different type.
This is particularily useful if the type contained in the optional is expensive to construct.
Typical use cases would be for Optional<std::string>, It would often only be needed to access the value as a StringRef.
Similar approach can be made for ArrayRef.
This function is enabled for any type that can be statically casted from the type contained in the Optional
I have reservations about this - for the same reason that StringRef, for instance, doesn't block being built from an rvalue (because you might (& in StringRef's case, do quite often) create one from a temporary only for use within a single statement).
Matching the sort of overload/semantics of getValueOr seems appropriate here.
Is there a particular example you have in mind where this would be a problem?