#ifndef SENTINEL_OPTIONAL_INL_H_ #error "Direct inclusion of this file is not allowed, include sentinel_optional.h" // For the sake of sane code completion. #include "sentinel_optional.h" #endif #include namespace NYT { //////////////////////////////////////////////////////////////////////////////// template constexpr TSentinelOptional::TSentinelOptional(std::nullopt_t) noexcept : Value_(TSentinel::Sentinel) { } template constexpr TSentinelOptional::TSentinelOptional(T value) noexcept : Value_(value) { } template constexpr TSentinelOptional::TSentinelOptional(std::optional opt) noexcept : Value_(opt ? *opt : TSentinel::Sentinel) { } template constexpr TSentinelOptional& TSentinelOptional::operator=(std::nullopt_t) noexcept { Value_ = TSentinel::Sentinel; return *this; } template constexpr TSentinelOptional& TSentinelOptional::operator=(T value) noexcept { Value_ = value; return *this; } template constexpr bool TSentinelOptional::has_value() const noexcept { return Value_ != TSentinel::Sentinel; } template constexpr TSentinelOptional::operator bool() const noexcept { return has_value(); } template constexpr T& TSentinelOptional::operator*() noexcept { return Value_; } template constexpr const T& TSentinelOptional::operator*() const noexcept { return Value_; } template constexpr T* TSentinelOptional::operator->() noexcept { return &Value_; } template constexpr const T* TSentinelOptional::operator->() const noexcept { return &Value_; } template T& TSentinelOptional::value() noexcept { YT_ASSERT(has_value()); return Value_; } template const T& TSentinelOptional::value() const noexcept { YT_ASSERT(has_value()); return Value_; } template constexpr T TSentinelOptional::value_or(T default_value) const noexcept { return has_value() ? Value_ : default_value; } template constexpr void TSentinelOptional::reset() noexcept { Value_ = TSentinel::Sentinel; } template constexpr TSentinelOptional::operator std::optional() const noexcept { return has_value() ? std::optional(Value_) : std::nullopt; } template constexpr bool TSentinelOptional::operator==(std::nullopt_t) const noexcept { return !has_value(); } //////////////////////////////////////////////////////////////////////////////// } // namespace NYT