mirror of
https://github.com/boostorg/optional.git
synced 2025-07-25 01:57:14 +02:00
Address unreachable code warning
In MSVC optional<T&>::value() emits a warning C4702: unreachable code because throw_exception is marked BOOST_RETURN. Otherwise the ternary code might have been preferable. This change addresses the warning while preserving the functionality. It replicates optional<T>::value() for consistency.
This commit is contained in:
committed by
Andrzej Krzemienski
parent
a7f49cbec8
commit
ead529af54
@ -151,7 +151,14 @@ public:
|
||||
T* get_ptr() const BOOST_NOEXCEPT { return ptr_; }
|
||||
T* operator->() const { BOOST_ASSERT(ptr_); return ptr_; }
|
||||
T& operator*() const { BOOST_ASSERT(ptr_); return *ptr_; }
|
||||
T& value() const { return ptr_ ? *ptr_ : (throw_exception(bad_optional_access()), *ptr_); }
|
||||
|
||||
T& value() const
|
||||
{
|
||||
if (this->is_initialized())
|
||||
return this->get();
|
||||
else
|
||||
throw_exception(bad_optional_access());
|
||||
}
|
||||
|
||||
bool operator!() const BOOST_NOEXCEPT { return ptr_ == 0; }
|
||||
BOOST_EXPLICIT_OPERATOR_BOOL_NOEXCEPT()
|
||||
|
Reference in New Issue
Block a user