UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
NotNull.h File Reference
#include "CoreTypes.h"
#include "Misc/IntrusiveUnsetOptionalState.h"
#include "Misc/UEOps.h"
#include "Templates/Requires.h"
#include "Templates/TypeHash.h"
#include "Traits/IsImplicitlyConstructible.h"
#include <type_traits>

Go to the source code of this file.

Macros

#define UE_ENABLE_NOTNULL_WRAPPER   (UE_BUILD_DEBUG || UE_BUILD_DEVELOPMENT)
 
#define UE_NOTNULL_FUNCTION_NON_NULL_RETURN_START   FUNCTION_NON_NULL_RETURN_START
 
#define UE_NOTNULL_FUNCTION_NON_NULL_RETURN_END   FUNCTION_NON_NULL_RETURN_END
 

Typedefs

template<typename T >
using TNotNull = T
 

Functions

template<typename T >
T && NotNullGet (T &&NotNull)
 

Macro Definition Documentation

◆ UE_ENABLE_NOTNULL_WRAPPER

#define UE_ENABLE_NOTNULL_WRAPPER   (UE_BUILD_DEBUG || UE_BUILD_DEVELOPMENT)

TNotNull is a wrapper template which is used to indicate that a pointer or handle is never intended to be null.

Design and rationale:

  • No default construction, construction with nullptr or comparison against nullptr. Attempting to do so will cause a compile error.
  • While intended for pointer types, it should be usable for anything else that is nullable, e.g. TFunction.
  • The pointer value is checked on construction or assignment, and then never after that. The only exception to this is a TNotNull in a moved-from state, which will not re-check the value. - see below.
  • TNotNull is movable. This allows things like TNotNull<TUniquePtr<T>> to be expressed, but means that a moved-from TNotNull variable can end up being null. However, users are never required to handle a variable in this state. If a variable is to be reused after it has been moved from (e.g. a data member of an object that isn't being destroyed) then code that made it null should assign a new non-null value to it before returning to user code or using it to construct or assign to another TNotNull. Users of your variable should never be allowed to see a null value. Compilers and static analyzers are allowed to assume that the pointer is not null and optimize and analyze accordingly.
  • The UE_ENABLE_NOTNULL_WRAPPER can be used to disable all checking and become an alias to the inner type, so there is no runtime overhead at all.

◆ UE_NOTNULL_FUNCTION_NON_NULL_RETURN_END

#define UE_NOTNULL_FUNCTION_NON_NULL_RETURN_END   FUNCTION_NON_NULL_RETURN_END

◆ UE_NOTNULL_FUNCTION_NON_NULL_RETURN_START

#define UE_NOTNULL_FUNCTION_NON_NULL_RETURN_START   FUNCTION_NON_NULL_RETURN_START

Typedef Documentation

◆ TNotNull

template<typename T >
using TNotNull = T

Function Documentation

◆ NotNullGet()

template<typename T >
T && NotNullGet ( T &&  NotNull)