This commit is contained in:
Simon Brand
2018-05-11 10:20:37 +01:00
parent 84a3a174be
commit 74155db243

View File

@@ -184,6 +184,19 @@ static constexpr unexpect_t unexpect{};
/// \exclude
namespace detail {
template<typename E>
[[noreturn]] constexpr void throw_exception(E &&e) {
#if defined(__EXCEPTIONS) || defined(_CPPUNWIND)
throw std::forward<E>(e);
#else
#ifdef _MSC_VER
__assume(0);
#else
__builtin_unreachable();
#endif
#endif
}
#ifndef TL_TRAITS_MUTEX
#define TL_TRAITS_MUTEX
// C++14-style aliases for brevity
@@ -1729,7 +1742,7 @@ public:
detail::enable_if_t<!std::is_void<U>::value> * = nullptr>
TL_EXPECTED_11_CONSTEXPR const U &value() const & {
if (!has_value())
throw bad_expected_access<E>(err().value());
detail::throw_exception(bad_expected_access<E>(err().value()));
return val();
}
/// \group value
@@ -1737,7 +1750,7 @@ public:
detail::enable_if_t<!std::is_void<U>::value> * = nullptr>
TL_EXPECTED_11_CONSTEXPR U &value() & {
if (!has_value())
throw bad_expected_access<E>(err().value());
detail::throw_exception(bad_expected_access<E>(err().value()));
return val();
}
/// \group value
@@ -1745,7 +1758,7 @@ public:
detail::enable_if_t<!std::is_void<U>::value> * = nullptr>
TL_EXPECTED_11_CONSTEXPR const U &&value() const && {
if (!has_value())
throw bad_expected_access<E>(err().value());
detail::throw_exception(bad_expected_access<E>(err().value()));
return std::move(val());
}
/// \group value
@@ -1753,7 +1766,7 @@ public:
detail::enable_if_t<!std::is_void<U>::value> * = nullptr>
TL_EXPECTED_11_CONSTEXPR U &&value() && {
if (!has_value())
throw bad_expected_access<E>(err().value());
detail::throw_exception(bad_expected_access<E>(err().value()));
return std::move(val());
}