From 0a243d8a48563ed388c17b77226c0b679d002614 Mon Sep 17 00:00:00 2001 From: ericLemanissier Date: Wed, 30 May 2018 16:00:56 +0200 Subject: [PATCH] added tests for non copyable not_null also, declared not_null move assignment as defaulted --- include/gsl/pointers | 1 + tests/notnull_tests.cpp | 32 +++++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) 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..4139edf0a 100644 --- a/tests/notnull_tests.cpp +++ b/tests/notnull_tests.cpp @@ -349,4 +349,34 @@ 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)); + CHECK(src.get() == nullptr); + CHECK(dst.get() != nullptr); + CHECK(*dst.get() == 42); + src = std::move(dst); + CHECK(dst.get() == nullptr); + CHECK(src.get() != nullptr); + CHECK(*src.get() == 42); + } + { + using NotNull1 = not_null>; + + // values are the same + CHECK((NotNull1(std::make_unique())->i == NotNull1(std::make_unique())->i)); + } +}