File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -145,14 +145,17 @@ public:
145145 not_null& operator-=(std::ptrdiff_t) = delete;
146146 void operator[](std::ptrdiff_t) const = delete;
147147
148- void swap(not_null<T>& other) { std::swap(ptr_, other.ptr_); }
148+ void swap(not_null<T>& other) noexcept(noexcept(std::swap(std::declval<T&>(), std::declval<T&>())))
149+ {
150+ std::swap(ptr_, other.ptr_);
151+ }
149152
150153private:
151154 T ptr_;
152155};
153156
154157template <typename T, std::enable_if_t<std::is_move_assignable<T>::value && std::is_move_constructible<T>::value, bool> = true>
155- void swap(not_null<T>& a, not_null<T>& b)
158+ void swap(not_null<T>& a, not_null<T>& b) noexcept(noexcept(a.swap(b)))
156159{
157160 a.swap(b);
158161}
Original file line number Diff line number Diff line change @@ -43,6 +43,8 @@ TEST(pointers_test, swap)
4343 gsl::not_null<std::unique_ptr<int >> a (std::make_unique<int >(0 ));
4444 gsl::not_null<std::unique_ptr<int >> b (std::make_unique<int >(1 ));
4545
46+ static_assert (noexcept (gsl::swap (a, b)), " not null unique_ptr should be noexcept-swappable" );
47+
4648 EXPECT_TRUE (*a == 0 );
4749 EXPECT_TRUE (*b == 1 );
4850
@@ -62,6 +64,8 @@ TEST(pointers_test, swap)
6264 gsl::strict_not_null<std::unique_ptr<int >> a{std::make_unique<int >(0 )};
6365 gsl::strict_not_null<std::unique_ptr<int >> b{std::make_unique<int >(1 )};
6466
67+ static_assert (noexcept (gsl::swap (a, b)), " strict not null unique_ptr should be noexcept-swappable" );
68+
6569 EXPECT_TRUE (*a == 0 );
6670 EXPECT_TRUE (*b == 1 );
6771
You can’t perform that action at this time.
0 commit comments