Go to the documentation of this file.
9 #ifndef SQUID__SRC_BASE_OPTIONAL_H
10 #define SQUID__SRC_BASE_OPTIONAL_H
13 #include <type_traits>
22 virtual const char*
what() const noexcept
override {
return "bad-optional-access"; }
27 template <typename Value>
34 static_assert(std::is_trivial<Value>::value,
"Value is trivial");
37 constexpr
explicit Optional(
const Value &v): value_(v), hasValue_(
true) {}
39 constexpr
explicit operator bool() const noexcept {
return hasValue_; }
40 constexpr
bool has_value() const noexcept {
return hasValue_; }
49 template <
class Other>
52 return hasValue_ ? value_ :
static_cast<Value
>(std::forward<Other>(defaultValue));
55 template <
class Other = Value>
58 value_ = std::forward<Other>(otherValue);
65 bool hasValue_ =
false;
constexpr Optional() noexcept
(limited) std::optional replacement (until we upgrade to C++17)
virtual ~BadOptionalAccess() noexcept=default
virtual const char * what() const noexcept override
constexpr bool has_value() const noexcept
std::bad_optional_access replacement (until we upgrade to C++17)
constexpr Optional(const Value &v)
constexpr Value value_or(Other &&defaultValue) const &
const Value & value() const &