diff --git a/include/gsl/pointers b/include/gsl/pointers index dc30166ee..bf26027aa 100644 --- a/include/gsl/pointers +++ b/include/gsl/pointers @@ -84,6 +84,7 @@ public: not_null(not_null&& other) = default; not_null(const not_null& other) = default; + not_null& operator=(not_null&& other) = default; not_null& operator=(const not_null& other) = default; constexpr T const & get() const diff --git a/tests/notnull_tests.cpp b/tests/notnull_tests.cpp index 83fc43057..146214cce 100644 --- a/tests/notnull_tests.cpp +++ b/tests/notnull_tests.cpp @@ -349,4 +349,38 @@ TEST_CASE("TestNotNullUniquePtrComparison") { // values are the same CHECK((NotNull1(std::make_unique())->i == NotNull1(std::make_unique())->i)); } -} \ No newline at end of file +} +static_assert(!std::is_assignable>, std::unique_ptr>::value, "not_null must be non copy constructible"); +static_assert(!std::is_copy_constructible>>::value, "not_null must be non copy constructible"); +static_assert(!std::is_copy_assignable>>::value, "not_null must be non copy assignable"); +static_assert(std::is_nothrow_move_constructible>>::value, "not_null must be no-throw move constructible"); +static_assert(std::is_nothrow_move_assignable>>::value, "not_null must be no-throw move assignable"); + + +TEST_CASE("TestNotNullUniquePtrMove") { + + { + using NotNull1 = not_null>; + + // values are the same + NotNull1 src(std::make_unique(42)); + NotNull1 dst(std::move(src)); + #ifdef GSL_THROW_ON_CONTRACT_VIOLATION + CHECK_THROWS_AS(!src.get(), fail_fast); + #endif + CHECK(dst.get()); + CHECK(*dst.get() == 42); + src = std::move(dst); + #ifdef GSL_THROW_ON_CONTRACT_VIOLATION + CHECK_THROWS_AS(!dst.get(), fail_fast); + #endif + CHECK(src.get()); + CHECK(*src.get() == 42); + } + { + using NotNull1 = not_null>; + + // values are the same + CHECK((NotNull1(std::make_unique())->i == NotNull1(std::make_unique())->i)); + } +}