getRefOrDefault overloads
Declared in <folly/GetRefUtil.h>
Returns optRef.value() if present, otherwise a const reference to a default-constructed static value_type. Avoids the copy that value_or({}) would make.
template<IsOptionalLike T>
T::value_type const&
getRefOrDefault(T const& optRef);
» more...
Returns *ptr if non-null, otherwise a const reference to a default-constructed static T. Avoids copies compared to a ternary that constructs a temporary default.
template<typename T>
T const&
getRefOrDefault(T const* ptr);
» more...
*ptr, or to a default-constructed value.| Name | Description |
|---|---|
| optRef | The optional-like object to read from. |
| ptr | The pointer to dereference, which may be null. |