Skip to content

Commit

Permalink
fix CTAD with deduction guide
Browse files Browse the repository at this point in the history
  • Loading branch information
ericLemanissier committed Apr 9, 2019
1 parent 9bfa724 commit cf2cd7b
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions include/gsl/pointers
Expand Up @@ -71,18 +71,12 @@ class not_null
public:
static_assert(std::is_assignable<T&, std::nullptr_t>::value, "T cannot be assigned nullptr.");

template <typename U, typename = std::enable_if_t<std::is_convertible<U, T>::value>>
template <typename U, typename = std::enable_if_t<std::is_convertible<U, T>::value && !std::is_same<std::nullptr_t, T>::value>>
constexpr not_null(U&& u) : ptr_(std::forward<U>(u))
{
Expects(ptr_ != nullptr);
}

template <typename = std::enable_if_t<!std::is_same<std::nullptr_t, T>::value>>
constexpr not_null(T u) : ptr_(u)
{
Expects(ptr_ != nullptr);
}

template <typename U, typename = std::enable_if_t<std::is_convertible<U, T>::value>>
constexpr not_null(const not_null<U>& other) : not_null(other.get())
{
Expand Down Expand Up @@ -120,6 +114,11 @@ private:
T ptr_;
};

#if defined(__cplusplus) && (__cplusplus >= 201703L)
template<class T>
not_null(T) -> not_null<T>;
#endif // #if defined(__cplusplus) && (__cplusplus >= 201703L)

template <class T>
auto make_not_null(T&& t) {
return not_null<std::remove_cv_t<std::remove_reference_t<T>>>{std::forward<T>(t)};
Expand Down

0 comments on commit cf2cd7b

Please sign in to comment.