From 30595c1f1d8bd481b2a7658323fa42e5f9a44029 Mon Sep 17 00:00:00 2001 From: saurabh singh Date: Wed, 31 May 2017 08:38:12 +0530 Subject: [PATCH] Restricting usage of owner to pointer types (#507) * Restricting usage of owner to pointer types * Removing an additional type that was created for testing * Added comment about the new constraint on owner * Adding dereference operator to not_null * Removing dereference operator changes for not-null * Removing dereference operator changes for not-null * Review comments --- include/gsl/gsl | 12 +++++++++++- tests/owner_tests.cpp | 12 ++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/include/gsl/gsl b/include/gsl/gsl index 65ce7eb..bc46aac 100644 --- a/include/gsl/gsl +++ b/include/gsl/gsl @@ -27,6 +27,7 @@ #include #include +#include #if defined(_MSC_VER) && _MSC_VER < 1910 #pragma push_macro("constexpr") @@ -53,7 +54,16 @@ namespace gsl using std::unique_ptr; using std::shared_ptr; -template +// +// owner +// +// +// owner is designed as a bridge for code that must deal directly with owning pointers for some reason +// +// T must be a pointer type +// - disallow construction from any type other than pointer type +// +template ::value>> using owner = T; // diff --git a/tests/owner_tests.cpp b/tests/owner_tests.cpp index b719b13..459c646 100644 --- a/tests/owner_tests.cpp +++ b/tests/owner_tests.cpp @@ -20,6 +20,8 @@ #include +#include + using namespace gsl; SUITE(owner_tests) @@ -34,6 +36,16 @@ SUITE(owner_tests) CHECK(*p == 121); delete p; } + + TEST(check_pointer_constraint) + { + #ifdef CONFIRM_COMPILATION_ERRORS + { + owner integerTest = 10; + owner> sharedPtrTest(new int(10)); + } + #endif + } } int main(int, const char* []) { return UnitTest::RunAllTests(); }