RealDocs

FMath: UE_REQUIRES

function Core Since 5.1
#include "Templates/Requires.h"
Access: public

Description

Preprocessor macro that wraps a C++20 requires-clause (or a SFINAE equivalent on older standards) to constrain template overloads inside FMath and other UE template-heavy code.

Caveats & Gotchas

  • UE_REQUIRES is a macro, not a function. It expands differently depending on the compiler and C++ standard in use — on C++20 it maps to a requires clause; on earlier standards it uses enable_if-style SFINAE. Do not treat it as a runtime check.
  • When reading FMath headers you will see UE_REQUIRES inside template parameter lists as a trailing comma-separated constraint. This is purely for the compiler — it has no runtime overhead or behaviour.

Signature

UE_REQUIRES(Condition)

Parameters

Name Type Description Default
Condition bool (constexpr expression) A compile-time boolean expression that must be true for the template overload to participate in overload resolution.

Example

How UE_REQUIRES constrains a template in FMath C++
// From the engine source — SinCos mixed-type overload:
template <
    typename T,
    typename U
    UE_REQUIRES(!std::is_same_v<T, U>)
>
static UE_FORCEINLINE_HINT void SinCos(T* ScalarSin, T* ScalarCos, U Value)
{
    SinCos(ScalarSin, ScalarCos, T(Value));
}

Tags

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.