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");
52 requires std::is_convertible_v<U, T>
53 constexpr explicit NotNull(U&& u)
54 : ptr_(std::forward<U>(u))
56 UASSERT_MSG(ptr_,
"Trying to construct NotNull from null");
60 requires std::is_convertible_v<U*, T>
61 constexpr NotNull(U& u)
62 : ptr_(std::addressof(u))
66 requires std::is_convertible_v<U, T>
67 constexpr NotNull(
const NotNull<U>& other)
68 : ptr_(other.GetBase())
70 UASSERT_MSG(ptr_,
"Trying to construct NotNull from null (moved-from) NotNull");
74 requires std::is_convertible_v<U, T>
75 constexpr NotNull(
NotNull<U>&& other)
76 : ptr_(std::move(other).GetBase())
78 UASSERT_MSG(ptr_,
"Trying to construct NotNull from null (moved-from) NotNull");
81 constexpr NotNull(std::nullptr_t) =
delete;
83 NotNull(
const NotNull& other)
noexcept =
default;
84 NotNull(
NotNull&& other)
noexcept =
default;
89 constexpr NotNull& operator=(std::nullptr_t) =
delete;
91 constexpr const T& GetBase()
const& {
92 UASSERT_MSG(ptr_,
"Trying to access a null (moved-from) NotNull");
96 constexpr T&& GetBase() && {
97 UASSERT_MSG(ptr_,
"Trying to access a null (moved-from) NotNull");
98 return std::move(ptr_);
101 constexpr operator
const T&()
const& {
return GetBase(); }
103 constexpr operator
bool() =
delete;
105 constexpr decltype(
auto) operator->()
const& {
return GetBase(); }
107 constexpr decltype(
auto) operator*()
const& {
return *GetBase(); }
109 constexpr decltype(
auto) operator->()
const& USERVER_IMPL_LIFETIME_BOUND
110 requires(!std::is_trivially_copyable_v<T>) && (!impl::IsStdSharedPtr<T>::value)
115 constexpr decltype(
auto) operator*()
const& USERVER_IMPL_LIFETIME_BOUND
116 requires(!std::is_trivially_copyable_v<T>) && (!impl::IsStdSharedPtr<T>::value)
121 template <
typename U>
122 constexpr bool operator==(
const NotNull<U>& other)
const& {
123 return GetBase() == other.GetBase();
126 template <
typename U>
127 constexpr bool operator!=(
const NotNull<U>& other)
const& {
128 return GetBase() != other.GetBase();