Merge pull request #876 from beinhaerter/make_notnull_noexcept

noexcept for make_(strict_)not_null and not_null comparisons
This commit is contained in:
Jordan Maples [MSFT] 2020-07-15 14:36:17 -07:00 committed by GitHub
commit f79ed1bb5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -113,7 +113,7 @@ private:
}; };
template <class T> template <class T>
auto make_not_null(T&& t) { auto make_not_null(T&& t) noexcept {
return not_null<std::remove_cv_t<std::remove_reference_t<T>>>{std::forward<T>(t)}; return not_null<std::remove_cv_t<std::remove_reference_t<T>>>{std::forward<T>(t)};
} }
@ -125,37 +125,37 @@ std::ostream& operator<<(std::ostream& os, const not_null<T>& val)
} }
template <class T, class U> template <class T, class U>
auto operator==(const not_null<T>& lhs, const not_null<U>& rhs) -> decltype(lhs.get() == rhs.get()) auto operator==(const not_null<T>& lhs, const not_null<U>& rhs) noexcept(noexcept(lhs.get() == rhs.get())) -> decltype(lhs.get() == rhs.get())
{ {
return lhs.get() == rhs.get(); return lhs.get() == rhs.get();
} }
template <class T, class U> template <class T, class U>
auto operator!=(const not_null<T>& lhs, const not_null<U>& rhs) -> decltype(lhs.get() != rhs.get()) auto operator!=(const not_null<T>& lhs, const not_null<U>& rhs) noexcept(noexcept(lhs.get() != rhs.get())) -> decltype(lhs.get() != rhs.get())
{ {
return lhs.get() != rhs.get(); return lhs.get() != rhs.get();
} }
template <class T, class U> template <class T, class U>
auto operator<(const not_null<T>& lhs, const not_null<U>& rhs) -> decltype(lhs.get() < rhs.get()) auto operator<(const not_null<T>& lhs, const not_null<U>& rhs) noexcept(noexcept(lhs.get() < rhs.get())) -> decltype(lhs.get() < rhs.get())
{ {
return lhs.get() < rhs.get(); return lhs.get() < rhs.get();
} }
template <class T, class U> template <class T, class U>
auto operator<=(const not_null<T>& lhs, const not_null<U>& rhs) -> decltype(lhs.get() <= rhs.get()) auto operator<=(const not_null<T>& lhs, const not_null<U>& rhs) noexcept(noexcept(lhs.get() <= rhs.get())) -> decltype(lhs.get() <= rhs.get())
{ {
return lhs.get() <= rhs.get(); return lhs.get() <= rhs.get();
} }
template <class T, class U> template <class T, class U>
auto operator>(const not_null<T>& lhs, const not_null<U>& rhs) -> decltype(lhs.get() > rhs.get()) auto operator>(const not_null<T>& lhs, const not_null<U>& rhs) noexcept(noexcept(lhs.get() > rhs.get())) -> decltype(lhs.get() > rhs.get())
{ {
return lhs.get() > rhs.get(); return lhs.get() > rhs.get();
} }
template <class T, class U> template <class T, class U>
auto operator>=(const not_null<T>& lhs, const not_null<U>& rhs) -> decltype(lhs.get() >= rhs.get()) auto operator>=(const not_null<T>& lhs, const not_null<U>& rhs) noexcept(noexcept(lhs.get() >= rhs.get())) -> decltype(lhs.get() >= rhs.get())
{ {
return lhs.get() >= rhs.get(); return lhs.get() >= rhs.get();
} }
@ -261,7 +261,7 @@ template <class T>
strict_not_null<T> operator+(std::ptrdiff_t, const strict_not_null<T>&) = delete; strict_not_null<T> operator+(std::ptrdiff_t, const strict_not_null<T>&) = delete;
template <class T> template <class T>
auto make_strict_not_null(T&& t) { auto make_strict_not_null(T&& t) noexcept {
return strict_not_null<std::remove_cv_t<std::remove_reference_t<T>>>{std::forward<T>(t)}; return strict_not_null<std::remove_cv_t<std::remove_reference_t<T>>>{std::forward<T>(t)};
} }