mirror of
https://github.com/TartanLlama/optional.git
synced 2025-08-02 11:24:26 +02:00
Fix noexcept
This commit is contained in:
18
optional.hpp
18
optional.hpp
@@ -271,11 +271,6 @@ struct optional_storage_base {
|
|||||||
TL_OPTIONAL_11_CONSTEXPR optional_storage_base() noexcept
|
TL_OPTIONAL_11_CONSTEXPR optional_storage_base() noexcept
|
||||||
: m_dummy(), m_has_value(false) {}
|
: m_dummy(), m_has_value(false) {}
|
||||||
|
|
||||||
optional_storage_base(const optional_storage_base &) = default;
|
|
||||||
optional_storage_base(optional_storage_base &&) noexcept = default;
|
|
||||||
optional_storage_base &operator=(const optional_storage_base &) = default;
|
|
||||||
optional_storage_base &operator=(optional_storage_base &&) noexcept = default;
|
|
||||||
|
|
||||||
template <class... U>
|
template <class... U>
|
||||||
TL_OPTIONAL_11_CONSTEXPR optional_storage_base(in_place_t, U &&... u)
|
TL_OPTIONAL_11_CONSTEXPR optional_storage_base(in_place_t, U &&... u)
|
||||||
: m_value(std::forward<U>(u)...), m_has_value(true) {}
|
: m_value(std::forward<U>(u)...), m_has_value(true) {}
|
||||||
@@ -300,17 +295,10 @@ template <class T> struct optional_storage_base<T, true> {
|
|||||||
TL_OPTIONAL_11_CONSTEXPR optional_storage_base() noexcept
|
TL_OPTIONAL_11_CONSTEXPR optional_storage_base() noexcept
|
||||||
: m_dummy(), m_has_value(false) {}
|
: m_dummy(), m_has_value(false) {}
|
||||||
|
|
||||||
optional_storage_base(const optional_storage_base &) = default;
|
|
||||||
optional_storage_base(optional_storage_base &&) noexcept = default;
|
|
||||||
optional_storage_base &operator=(const optional_storage_base &) = default;
|
|
||||||
optional_storage_base &operator=(optional_storage_base &&) noexcept = default;
|
|
||||||
|
|
||||||
template <class... U>
|
template <class... U>
|
||||||
TL_OPTIONAL_11_CONSTEXPR optional_storage_base(in_place_t, U &&... u)
|
TL_OPTIONAL_11_CONSTEXPR optional_storage_base(in_place_t, U &&... u)
|
||||||
: m_value(std::forward<U>(u)...), m_has_value(true) {}
|
: m_value(std::forward<U>(u)...), m_has_value(true) {}
|
||||||
|
|
||||||
~optional_storage_base() = default;
|
|
||||||
|
|
||||||
struct dummy {};
|
struct dummy {};
|
||||||
union {
|
union {
|
||||||
dummy m_dummy;
|
dummy m_dummy;
|
||||||
@@ -995,7 +983,7 @@ public:
|
|||||||
///
|
///
|
||||||
/// If `rhs` contains a value, the stored value is direct-initialized with it.
|
/// If `rhs` contains a value, the stored value is direct-initialized with it.
|
||||||
/// Otherwise, the constructed optional is empty.
|
/// Otherwise, the constructed optional is empty.
|
||||||
TL_OPTIONAL_11_CONSTEXPR optional(optional &&rhs) = default;
|
TL_OPTIONAL_11_CONSTEXPR optional(optional &&rhs) = default;
|
||||||
|
|
||||||
/// Constructs the stored value in-place using the given arguments.
|
/// Constructs the stored value in-place using the given arguments.
|
||||||
/// \group in_place
|
/// \group in_place
|
||||||
@@ -1098,9 +1086,7 @@ public:
|
|||||||
///
|
///
|
||||||
/// Moves the value from `rhs` if there is one. Otherwise resets the stored
|
/// Moves the value from `rhs` if there is one. Otherwise resets the stored
|
||||||
/// value in `*this`.
|
/// value in `*this`.
|
||||||
optional &operator=(optional &&rhs) noexcept(
|
optional &operator=(optional &&rhs) = default;
|
||||||
std::is_nothrow_move_assignable<T>::value
|
|
||||||
&&std::is_nothrow_move_constructible<T>::value) = default;
|
|
||||||
|
|
||||||
// TODO conditionally delete, check exception guarantee
|
// TODO conditionally delete, check exception guarantee
|
||||||
/// Assigns the stored value from `u`, destroying the old value if there was
|
/// Assigns the stored value from `u`, destroying the old value if there was
|
||||||
|
@@ -63,8 +63,8 @@ TEST_CASE("Noexcept", "[noexcept]") {
|
|||||||
using nothrow_opt = tl::optional<nothrow_move>;
|
using nothrow_opt = tl::optional<nothrow_move>;
|
||||||
using throw_opt = tl::optional<throw_move>;
|
using throw_opt = tl::optional<throw_move>;
|
||||||
|
|
||||||
REQUIRE(noexcept(nothrow_opt{std::declval<nothrow_opt>()}));
|
REQUIRE(std::is_nothrow_move_constructible<nothrow_opt>::value);
|
||||||
REQUIRE(!noexcept(throw_opt{std::declval<throw_opt>()}));
|
REQUIRE(!std::is_nothrow_move_constructible<throw_opt>::value);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user