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(); }