33 static_assert(!std::is_reference_v<T>,
"NotNull does not work with references");
34 static_assert(!std::is_const_v<T>,
"NotNull does not work with const T");
37 constexpr explicit NotNull() =
delete;
39 constexpr explicit NotNull(
const T& u)
42 UASSERT_MSG(ptr_,
"Trying to construct NotNull from null");
45 constexpr explicit NotNull(T&& u)
48 UASSERT_MSG(ptr_,
"Trying to construct NotNull from null");
51 template <
typename U,
typename = std::enable_if_t<std::is_convertible_v<U, T>>>
52 constexpr explicit NotNull(U&& u)
53 : ptr_(std::forward<U>(u))
55 UASSERT_MSG(ptr_,
"Trying to construct NotNull from null");
58 template <
typename U,
typename = std::enable_if_t<std::is_convertible_v<U*, T>>>
59 constexpr NotNull(U& u)
60 : ptr_(std::addressof(u))
63 template <
typename U,
typename = std::enable_if_t<std::is_convertible_v<U, T>>>
64 constexpr NotNull(
const NotNull<U>& other)
65 : ptr_(other.GetBase())
67 UASSERT_MSG(ptr_,
"Trying to construct NotNull from null (moved-from) NotNull");
70 template <
typename U,
typename = std::enable_if_t<std::is_convertible_v<U, T>>>
71 constexpr NotNull(
NotNull<U>&& other)
72 : ptr_(std::move(other).GetBase())
74 UASSERT_MSG(ptr_,
"Trying to construct NotNull from null (moved-from) NotNull");
77 constexpr NotNull(std::nullptr_t) =
delete;
79 NotNull(
const NotNull& other)
noexcept =
default;
80 NotNull(
NotNull&& other)
noexcept =
default;
85 constexpr NotNull& operator=(std::nullptr_t) =
delete;
87 constexpr const T& GetBase()
const& {
88 UASSERT_MSG(ptr_,
"Trying to access a null (moved-from) NotNull");
92 constexpr T&& GetBase() && {
93 UASSERT_MSG(ptr_,
"Trying to access a null (moved-from) NotNull");
94 return std::move(ptr_);
97 constexpr operator
const T&()
const& {
return GetBase(); }
99 constexpr operator
bool() =
delete;
101 constexpr decltype(
auto) operator->()
const& {
return GetBase(); }
103 constexpr decltype(
auto) operator*()
const& {
return *GetBase(); }
105 constexpr decltype(
auto) operator->()
const& USERVER_IMPL_LIFETIME_BOUND
106 requires(!std::is_trivially_copyable_v<T>) && (!impl::IsStdSharedPtr<T>::value)
111 constexpr decltype(
auto) operator*()
const& USERVER_IMPL_LIFETIME_BOUND
112 requires(!std::is_trivially_copyable_v<T>) && (!impl::IsStdSharedPtr<T>::value)
117 template <
typename U>
118 constexpr bool operator==(
const NotNull<U>& other)
const& {
119 return GetBase() == other.GetBase();
122 template <
typename U>
123 constexpr bool operator!=(
const NotNull<U>& other)
const& {
124 return GetBase() != other.GetBase();