mirror of
https://github.com/TartanLlama/expected.git
synced 2025-09-26 04:50:55 +02:00
Don't copy unexpected object on throwing with exceptions disabled
This commit is contained in:
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.14)
|
|||||||
project(tl-expected
|
project(tl-expected
|
||||||
HOMEPAGE_URL https://tl.tartanllama.xyz
|
HOMEPAGE_URL https://tl.tartanllama.xyz
|
||||||
DESCRIPTION "C++11/14/17 std::expected with functional-style extensions"
|
DESCRIPTION "C++11/14/17 std::expected with functional-style extensions"
|
||||||
VERSION 1.2.0
|
VERSION 1.3.0
|
||||||
LANGUAGES CXX)
|
LANGUAGES CXX)
|
||||||
|
|
||||||
include(CMakePackageConfigHelpers)
|
include(CMakePackageConfigHelpers)
|
||||||
|
@@ -17,7 +17,7 @@
|
|||||||
#define TL_EXPECTED_HPP
|
#define TL_EXPECTED_HPP
|
||||||
|
|
||||||
#define TL_EXPECTED_VERSION_MAJOR 1
|
#define TL_EXPECTED_VERSION_MAJOR 1
|
||||||
#define TL_EXPECTED_VERSION_MINOR 2
|
#define TL_EXPECTED_VERSION_MINOR 3
|
||||||
#define TL_EXPECTED_VERSION_PATCH 0
|
#define TL_EXPECTED_VERSION_PATCH 0
|
||||||
|
|
||||||
#include <exception>
|
#include <exception>
|
||||||
@@ -219,20 +219,11 @@ struct unexpect_t {
|
|||||||
};
|
};
|
||||||
static constexpr unexpect_t unexpect{};
|
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
|
#ifdef TL_EXPECTED_EXCEPTIONS_ENABLED
|
||||||
throw std::forward<E>(e);
|
#define TL_EXPECTED_THROW_EXCEPTION(e) throw((e));
|
||||||
#else
|
#elif defined(_MSC_VER)
|
||||||
(void)e;
|
#define TL_EXPECTED_THROW_EXCEPTION(e) std::terminate();
|
||||||
#ifdef _MSC_VER
|
|
||||||
__assume(0);
|
|
||||||
#else
|
|
||||||
__builtin_unreachable();
|
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef TL_TRAITS_MUTEX
|
#ifndef TL_TRAITS_MUTEX
|
||||||
#define TL_TRAITS_MUTEX
|
#define TL_TRAITS_MUTEX
|
||||||
@@ -2024,28 +2015,28 @@ public:
|
|||||||
detail::enable_if_t<!std::is_void<U>::value> * = nullptr>
|
detail::enable_if_t<!std::is_void<U>::value> * = nullptr>
|
||||||
TL_EXPECTED_11_CONSTEXPR const U &value() const & {
|
TL_EXPECTED_11_CONSTEXPR const U &value() const & {
|
||||||
if (!has_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();
|
return val();
|
||||||
}
|
}
|
||||||
template <class U = T,
|
template <class U = T,
|
||||||
detail::enable_if_t<!std::is_void<U>::value> * = nullptr>
|
detail::enable_if_t<!std::is_void<U>::value> * = nullptr>
|
||||||
TL_EXPECTED_11_CONSTEXPR U &value() & {
|
TL_EXPECTED_11_CONSTEXPR U &value() & {
|
||||||
if (!has_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();
|
return val();
|
||||||
}
|
}
|
||||||
template <class U = T,
|
template <class U = T,
|
||||||
detail::enable_if_t<!std::is_void<U>::value> * = nullptr>
|
detail::enable_if_t<!std::is_void<U>::value> * = nullptr>
|
||||||
TL_EXPECTED_11_CONSTEXPR const U &&value() const && {
|
TL_EXPECTED_11_CONSTEXPR const U &&value() const && {
|
||||||
if (!has_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());
|
return std::move(val());
|
||||||
}
|
}
|
||||||
template <class U = T,
|
template <class U = T,
|
||||||
detail::enable_if_t<!std::is_void<U>::value> * = nullptr>
|
detail::enable_if_t<!std::is_void<U>::value> * = nullptr>
|
||||||
TL_EXPECTED_11_CONSTEXPR U &&value() && {
|
TL_EXPECTED_11_CONSTEXPR U &&value() && {
|
||||||
if (!has_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());
|
return std::move(val());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user