diff options
author | Jordan Maples [MSFT] <49793787+JordanMaples@users.noreply.github.com> | 2020-08-26 17:48:26 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-26 17:48:26 -0700 |
commit | 6c518638acf576adebd922e7051124c805eef95f (patch) | |
tree | b0ef0e8b884adc71b22d240fcb435bd91412fe8a | |
parent | b6451c5db078e0c6445471e3d34c47404f3c6b5a (diff) | |
parent | 4a4bb3c13a6c782b9207bba9ece72b123ff76431 (diff) | |
download | Microsoft-GSL-6c518638acf576adebd922e7051124c805eef95f.tar.gz |
Merge pull request #921 from JordanMaples/not_null-changes
not_null improvements
-rw-r--r-- | include/gsl/pointers | 7 |
1 files 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 <typename = std::enable_if_t<!std::is_same<std::nullptr_t, T>::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<std::is_copy_constructible<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 |