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,14 @@ 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 { std::swap(ptr_, other.ptr_); }
149149
150150private:
151151 T ptr_;
152152};
153153
154154template <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)
155+ void swap(not_null<T>& a, not_null<T>& b) noexcept
156156{
157157 a.swap(b);
158158}
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