Add missing noexcept specifications to methods of optional<T&>

This commit is contained in:
Deniz Evrenci
2019-07-08 19:35:48 +09:00
parent 5c4876059c
commit 084a9001f4

View File

@ -1939,12 +1939,12 @@ public:
template <class U = T, template <class U = T,
detail::enable_if_t<!detail::is_optional<detail::decay_t<U>>::value> detail::enable_if_t<!detail::is_optional<detail::decay_t<U>>::value>
* = nullptr> * = 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<U>::value, "U must be an lvalue"); static_assert(std::is_lvalue_reference<U>::value, "U must be an lvalue");
} }
template <class U> template <class U>
constexpr explicit optional(const optional<U> &rhs) : optional(*rhs) {} constexpr explicit optional(const optional<U> &rhs) noexcept : optional(*rhs) {}
/// No-op /// No-op
~optional() = default; ~optional() = default;
@ -1977,7 +1977,7 @@ public:
/// ///
/// Rebinds this optional to the referee of `rhs` if there is one. Otherwise /// Rebinds this optional to the referee of `rhs` if there is one. Otherwise
/// resets the stored value in `*this`. /// resets the stored value in `*this`.
template <class U> optional &operator=(const optional<U> &rhs) { template <class U> optional &operator=(const optional<U> &rhs) noexcept {
m_value = std::addressof(rhs.value()); m_value = std::addressof(rhs.value());
return *this; return *this;
} }
@ -1996,14 +1996,14 @@ public:
void swap(optional &rhs) noexcept { std::swap(m_value, rhs.m_value); } void swap(optional &rhs) noexcept { std::swap(m_value, rhs.m_value); }
/// Returns a pointer to the stored 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 /// 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; } 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` /// Returns the stored value if there is one, otherwise returns `u`
template <class U> constexpr T value_or(U &&u) const & { template <class U> constexpr T value_or(U &&u) const & noexcept {
static_assert(std::is_copy_constructible<T>::value && static_assert(std::is_copy_constructible<T>::value &&
std::is_convertible<U &&, T>::value, std::is_convertible<U &&, T>::value,
"T must be copy constructible and convertible from U"); "T must be copy constructible and convertible from U");
@ -2032,7 +2032,7 @@ public:
} }
/// \group value_or /// \group value_or
template <class U> TL_OPTIONAL_11_CONSTEXPR T value_or(U &&u) && { template <class U> TL_OPTIONAL_11_CONSTEXPR T value_or(U &&u) && noexcept {
static_assert(std::is_move_constructible<T>::value && static_assert(std::is_move_constructible<T>::value &&
std::is_convertible<U &&, T>::value, std::is_convertible<U &&, T>::value,
"T must be move constructible and convertible from U"); "T must be move constructible and convertible from U");