From 4a4bb3c13a6c782b9207bba9ece72b123ff76431 Mon Sep 17 00:00:00 2001 From: Jordan Maples Date: Wed, 26 Aug 2020 16:51:58 -0700 Subject: [PATCH] adding changes suggested by Jonathan Wakely --- include/gsl/pointers | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/include/gsl/pointers b/include/gsl/pointers index 2418ec7..874583d 100644 --- a/include/gsl/pointers +++ b/include/gsl/pointers @@ -72,7 +72,7 @@ public: } template ::value>> - constexpr not_null(T u) : ptr_(u) + constexpr not_null(T u) : ptr_(std::move(u)) { Expects(ptr_ != nullptr); } @@ -84,15 +84,14 @@ public: not_null(const not_null& other) = default; not_null& operator=(const not_null& other) = default; - - constexpr T get() const + constexpr std::conditional_t::value, T, const T&> get() const { Ensures(ptr_ != nullptr); return ptr_; } constexpr operator T() const { return get(); } - constexpr T operator->() const { return get(); } + constexpr decltype(auto) operator->() const { return get(); } constexpr decltype(auto) operator*() const { return *get(); } // prevents compilation when someone attempts to assign a null pointer constant