#define TL_EXPECTED_HPP
#define TL_EXPECTED_VERSION_MAJOR 1
-#define TL_EXPECTED_VERSION_MINOR 2
-#define TL_EXPECTED_VERSION_PATCH 0
+#define TL_EXPECTED_VERSION_MINOR 3
+#define TL_EXPECTED_VERSION_PATCH 1
#include <exception>
#include <functional>
#define TL_EXPECTED_GCC55
#endif
+#ifdef _MSVC_LANG
+#define TL_CPLUSPLUS _MSVC_LANG
+#else
+#define TL_CPLUSPLUS __cplusplus
+#endif
+
#if !defined(TL_ASSERT)
//can't have assert in constexpr in C++11 and GCC 4.9 has a compiler bug
#if (TL_CPLUSPLUS > 201103L) && !defined(TL_EXPECTED_GCC49)
std::is_trivially_destructible<T>
#endif
-#ifdef _MSVC_LANG
-#define TL_CPLUSPLUS _MSVC_LANG
-#else
-#define TL_CPLUSPLUS __cplusplus
-#endif
-
#if TL_CPLUSPLUS > 201103L
#define TL_EXPECTED_CXX14
#endif
};
static constexpr unexpect_t unexpect{};
-namespace detail {
-template <typename E>
-[[noreturn]] TL_EXPECTED_11_CONSTEXPR void throw_exception(E &&e) {
#ifdef TL_EXPECTED_EXCEPTIONS_ENABLED
- throw std::forward<E>(e);
+#define TL_EXPECTED_THROW_EXCEPTION(e) throw((e));
#else
- (void)e;
-#ifdef _MSC_VER
- __assume(0);
-#else
- __builtin_unreachable();
-#endif
+#define TL_EXPECTED_THROW_EXCEPTION(e) std::terminate();
#endif
-}
+namespace detail {
#ifndef TL_TRAITS_MUTEX
#define TL_TRAITS_MUTEX
// C++14-style aliases for brevity
detail::enable_if_t<!std::is_void<U>::value> * = nullptr>
TL_EXPECTED_11_CONSTEXPR const U &value() const & {
if (!has_value())
- detail::throw_exception(bad_expected_access<E>(err().value()));
+ TL_EXPECTED_THROW_EXCEPTION(bad_expected_access<E>(err().value()));
return val();
}
template <class U = T,
detail::enable_if_t<!std::is_void<U>::value> * = nullptr>
TL_EXPECTED_11_CONSTEXPR U &value() & {
if (!has_value())
- detail::throw_exception(bad_expected_access<E>(err().value()));
+ TL_EXPECTED_THROW_EXCEPTION(bad_expected_access<E>(err().value()));
return val();
}
template <class U = T,
detail::enable_if_t<!std::is_void<U>::value> * = nullptr>
TL_EXPECTED_11_CONSTEXPR const U &&value() const && {
if (!has_value())
- detail::throw_exception(bad_expected_access<E>(std::move(err()).value()));
+ TL_EXPECTED_THROW_EXCEPTION(bad_expected_access<E>(std::move(err()).value()));
return std::move(val());
}
template <class U = T,
detail::enable_if_t<!std::is_void<U>::value> * = nullptr>
TL_EXPECTED_11_CONSTEXPR U &&value() && {
if (!has_value())
- detail::throw_exception(bad_expected_access<E>(std::move(err()).value()));
+ TL_EXPECTED_THROW_EXCEPTION(bad_expected_access<E>(std::move(err()).value()));
return std::move(val());
}