Skip to content

Commit

Permalink
adding changes suggested by Jonathan Wakely
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Maples committed Aug 26, 2020
1 parent b6451c5 commit 4a4bb3c
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions include/gsl/pointers
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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
Expand Down

0 comments on commit 4a4bb3c

Please sign in to comment.