// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details1#pragma once23#include "Luau/Common.h"45#include <functional>67namespace Luau8{910/** A non-owning, non-null pointer to a T.11*12* A NotNull<T> is notionally identical to a T* with the added restriction that13* it can never store nullptr.14*15* The sole conversion rule from T* to NotNull<T> is the single-argument16* constructor, which is intentionally marked explicit. This constructor17* performs a runtime test to verify that the passed pointer is never nullptr.18*19* Pointer arithmetic, increment, decrement, and array indexing are all20* forbidden.21*22* An implicit coercion from NotNull<T> to T* is afforded, as are the pointer23* indirection and member access operators. (*p and p->prop)24*25* The explicit delete statement is permitted (but not recommended) on a26* NotNull<T> through this implicit conversion.27*/28template<typename T>29struct NotNull30{31explicit NotNull(T* t)32: ptr(t)33{34LUAU_ASSERT(t);35}3637explicit NotNull(std::nullptr_t) = delete;38void operator=(std::nullptr_t) = delete;3940template<typename U>41NotNull(NotNull<U> other)42: ptr(other.get())43{44}4546operator T*() const noexcept47{48return ptr;49}5051T& operator*() const noexcept52{53return *ptr;54}5556T* operator->() const noexcept57{58return ptr;59}6061template<typename U>62bool operator==(NotNull<U> other) const noexcept63{64return get() == other.get();65}6667template<typename U>68bool operator!=(NotNull<U> other) const noexcept69{70return get() != other.get();71}7273operator bool() const noexcept = delete;7475T& operator[](int) = delete;7677T& operator+(int) = delete;78T& operator-(int) = delete;7980T* get() const noexcept81{82return ptr;83}8485private:86T* ptr;87};8889} // namespace Luau9091namespace std92{9394template<typename T>95struct hash<Luau::NotNull<T>>96{97size_t operator()(const Luau::NotNull<T>& p) const98{99return std::hash<T*>()(p.get());100}101};102103} // namespace std104105106