diff --git a/include/tl/optional.hpp b/include/tl/optional.hpp index 4d41e54..9cba0b8 100644 --- a/include/tl/optional.hpp +++ b/include/tl/optional.hpp @@ -1939,12 +1939,12 @@ public: template >::value> * = nullptr> - constexpr optional(U &&u) : m_value(std::addressof(u)) { + constexpr optional(U &&u) noexcept : m_value(std::addressof(u)) { static_assert(std::is_lvalue_reference::value, "U must be an lvalue"); } template - constexpr explicit optional(const optional &rhs) : optional(*rhs) {} + constexpr explicit optional(const optional &rhs) noexcept : optional(*rhs) {} /// No-op ~optional() = default; @@ -1977,7 +1977,7 @@ public: /// /// Rebinds this optional to the referee of `rhs` if there is one. Otherwise /// resets the stored value in `*this`. - template optional &operator=(const optional &rhs) { + template optional &operator=(const optional &rhs) noexcept { m_value = std::addressof(rhs.value()); return *this; } @@ -1996,14 +1996,14 @@ public: void swap(optional &rhs) noexcept { std::swap(m_value, rhs.m_value); } /// Returns a pointer to the stored value - constexpr const T *operator->() const { return m_value; } + constexpr const T *operator->() const noexcept { return m_value; } - TL_OPTIONAL_11_CONSTEXPR T *operator->() { return m_value; } + TL_OPTIONAL_11_CONSTEXPR T *operator->() noexcept { return m_value; } /// Returns the stored value - TL_OPTIONAL_11_CONSTEXPR T &operator*() { return *m_value; } + TL_OPTIONAL_11_CONSTEXPR T &operator*() noexcept { return *m_value; } - constexpr const T &operator*() const { return *m_value; } + constexpr const T &operator*() const noexcept { return *m_value; } constexpr bool has_value() const noexcept { return m_value != nullptr; } @@ -2024,7 +2024,7 @@ public: } /// Returns the stored value if there is one, otherwise returns `u` - template constexpr T value_or(U &&u) const & { + template constexpr T value_or(U &&u) const & noexcept { static_assert(std::is_copy_constructible::value && std::is_convertible::value, "T must be copy constructible and convertible from U"); @@ -2032,7 +2032,7 @@ public: } /// \group value_or - template TL_OPTIONAL_11_CONSTEXPR T value_or(U &&u) && { + template TL_OPTIONAL_11_CONSTEXPR T value_or(U &&u) && noexcept { static_assert(std::is_move_constructible::value && std::is_convertible::value, "T must be move constructible and convertible from U");