introduce gsl::swap for swapping gsl::not_null (#1160)

fixes: https://github.com/microsoft/GSL/issues/1129

* create gsl::swap<T>(T&, T&) which wraps std::swap
* specialize gsl::swap<T>(gsl::not_null<T>&, gsl::not_null<T>&)
* add tests
This commit is contained in:
Carson Radtke authored and GitHub committed 2024-12-13 15:16:53 -06:00
1 parent 8a0e3d8a9b
commit 272463043e
5 files changed
+53

No files matched your search

+8
View File
@@ -139,10 +139,18 @@ public:
not_null& operator-=(std::ptrdiff_t) = delete;
void operator[](std::ptrdiff_t) const = delete;
void swap(not_null<T>& other) { std::swap(ptr_, other.ptr_); }
private:
T ptr_;
};
template <typename T, typename = std::enable_if_t<std::is_move_assignable<T>::value && std::is_move_constructible<T>::value>>
void swap(not_null<T>& a, not_null<T>& b)
{
a.swap(b);
}
template <class T>
auto make_not_null(T&& t) noexcept
{