RealDocs

TArray — UE_REQUIRES constraint

function Core Since 5.1
#include "Containers/Array.h"
Access: public

Description

Template constraint applied to TArray cross-type constructors and assignment operators. Ensures the source element type is compatible (implicitly constructible or assignable) with the destination element type before the overload participates in overload resolution.

Caveats & Gotchas

  • UE_REQUIRES expands to a C++20 `requires` clause on supported compilers and falls back to a std::enable_if workaround on older toolchains. If your build uses an older compiler standard, error messages for constraint violations may be significantly less readable.
  • The constraint only checks type compatibility, not allocator compatibility. You can copy between TArray<int32, FDefaultAllocator> and TArray<int32, TInlineAllocator<4>>, but the inline buffer will be ignored and heap memory will be used on the destination.

Signature

UE_REQUIRES(UE::Core::Private::TArrayElementsAreCompatible_V<ElementType, const OtherElementType&>)

Example

Cross-type array conversion enabled by UE_REQUIRES C++
TArray<int32> IntArray = {1, 2, 3};
// Compiles because int32 is convertible to int64:
TArray<int64> LongArray(IntArray);

// Would NOT compile — UE_REQUIRES rejects the overload:
// TArray<FVector> VecArray(IntArray);

Version History

Introduced in: 5.1

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.