UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
TRange< ElementType > Class Template Reference

#include <Range.h>

Public Types

typedef TRangeBound< ElementType > BoundsType
 
typedef TCallTraits< ElementType >::ParamType ElementValueOrConstRef
 

Public Member Functions

 TRange ()
 
 TRange (ElementValueOrConstRef A)
 
 TRange (ElementValueOrConstRef A, ElementValueOrConstRef B)
 
 TRange (const BoundsType &InLowerBound, const BoundsType &InUpperBound)
 
bool operator== (const TRange &Other) const
 
bool operator!= (const TRange &Other) const
 
bool Adjoins (const TRange &Other) const
 
bool Conjoins (const TRange &X, const TRange &Y) const
 
bool Contains (ElementValueOrConstRef Element) const
 
bool Contains (const TRange &Other) const
 
bool Contiguous (const TRange &Other) const
 
BoundsType GetLowerBound () const
 
void SetLowerBound (const BoundsType &NewLowerBound)
 
void SetLowerBoundValue (ElementValueOrConstRef NewLowerBoundValue)
 
ElementValueOrConstRef GetLowerBoundValue () const
 
BoundsType GetUpperBound () const
 
void SetUpperBound (const BoundsType &NewUpperBound)
 
void SetUpperBoundValue (ElementValueOrConstRef NewUpperBoundValue)
 
ElementValueOrConstRef GetUpperBoundValue () const
 
bool HasLowerBound () const
 
bool HasUpperBound () const
 
bool IsDegenerate () const
 
bool IsEmpty () const
 
bool Overlaps (const TRange &Other) const
 
template<typename DifferenceType >
DifferenceType Size () const
 
TArray< TRangeSplit (ElementValueOrConstRef Element) const
 

Static Public Member Functions

static TArray< TRangeDifference (const TRange &X, const TRange &Y)
 
static TRange Hull (const TRange &X, const TRange &Y)
 
static TRange Hull (const TArray< TRange > &Ranges)
 
static TRange Intersection (const TRange &X, const TRange &Y)
 
static TRange Intersection (const TArray< TRange > &Ranges)
 
static TArray< TRangeUnion (const TRange &X, const TRange &Y)
 
static UE_FORCEINLINE_HINT TRange All ()
 
static UE_FORCEINLINE_HINT TRange AtLeast (ElementValueOrConstRef Value)
 
static UE_FORCEINLINE_HINT TRange AtMost (ElementValueOrConstRef Value)
 
static UE_FORCEINLINE_HINT TRange Empty ()
 
static UE_FORCEINLINE_HINT TRange Exclusive (ElementValueOrConstRef Min, ElementValueOrConstRef Max)
 
static UE_FORCEINLINE_HINT TRange GreaterThan (ElementValueOrConstRef Value)
 
static UE_FORCEINLINE_HINT TRange Inclusive (ElementValueOrConstRef Min, ElementValueOrConstRef Max)
 
static UE_FORCEINLINE_HINT TRange LessThan (ElementValueOrConstRef Value)
 

Friends

class FArchiveoperator<< (class FArchive &Ar, TRange &Range)
 
uint32 GetTypeHash (const TRange &Range)
 

Detailed Description

template<typename ElementType>
class TRange< ElementType >

Template for ranges.

Note: This class is not intended for interval arithmetic (see TInterval for that).

A range represents a contiguous set of elements that only stores the set's lower and upper bound values (aka. endpoints) for storage efficiency. Bound values may be exclusive (the value is not part of the range), inclusive (the value is part of the range) or open (there is no limit on the values).

The template's primary focus is on continuous ranges, but it can be used for the representation of discrete ranges as well. The element type of discrete ranges has a well-defined stepping, such as an integer or a date, that separates the neighboring elements. This is in contrast with continuous ranges in which the step sizes, such as floats or time spans, are not of interest, and other elements may be found between any two elements (although, in practice, all ranges are discrete due to the limited precision of numerical values in computers).

When working with ranges, the user of this template is responsible for correctly interpreting the range endpoints. Certain semantics will be different depending on whether the range is interpreted in a continuous or discrete domain.

Iteration of a discrete range [A, B) includes the elements A to B-1. The elements of continuous ranges are generally not meant to be iterated. It is also important to consider the equivalence of different representations of discrete ranges. For example, the ranges [2, 6), (1, 5] and [2, 5] are equivalent in discrete domains, but different in continuous ones. In order to keep this class simple, we have not included canonicalization functions or auxiliary template parameters, such as unit and min/max domain elements. For ease of use in most common use cases, it is recommended to limit all operations to canonical ranges of the form [A, B) in which the lower bound is included and the upper bound is excluded from the range.

Parameters
ElementTypeThe type of elements represented by the range
See also
RangeBound, TInterval

Member Typedef Documentation

◆ BoundsType

template<typename ElementType >
typedef TRangeBound<ElementType> TRange< ElementType >::BoundsType

◆ ElementValueOrConstRef

template<typename ElementType >
typedef TCallTraits<ElementType>::ParamType TRange< ElementType >::ElementValueOrConstRef

Constructor & Destructor Documentation

◆ TRange() [1/4]

template<typename ElementType >
TRange< ElementType >::TRange ( )
inline

Default constructor (no initialization).

◆ TRange() [2/4]

template<typename ElementType >
TRange< ElementType >::TRange ( ElementValueOrConstRef  A)
inlineexplicit

Create a range with a single element.

The created range is of the form [A, A].

Parameters
AThe element in the range.

◆ TRange() [3/4]

template<typename ElementType >
TRange< ElementType >::TRange ( ElementValueOrConstRef  A,
ElementValueOrConstRef  B 
)
inlineexplicit

Create and initializes a new range with the given lower and upper bounds.

The created range is of the form [A, B).

Parameters
AThe range's lower bound value (inclusive).
BThe range's upper bound value (exclusive).

◆ TRange() [4/4]

template<typename ElementType >
TRange< ElementType >::TRange ( const BoundsType InLowerBound,
const BoundsType InUpperBound 
)
inlineexplicit

Create and initializes a new range with the given lower and upper bounds.

Parameters
InLowerBoundThe range's lower bound.
InUpperBoundThe range's upper bound.

Member Function Documentation

◆ Adjoins()

template<typename ElementType >
bool TRange< ElementType >::Adjoins ( const TRange< ElementType > &  Other) const
inline

Check whether this range adjoins to another.

Two ranges are adjoint if they are next to each other without overlapping, i.e. [A, B) and [B, C) or [A, B] and (B, C)

Parameters
OtherThe other range.
Returns
true if this range adjoins the other, false otherwise.

◆ All()

template<typename ElementType >
static UE_FORCEINLINE_HINT TRange TRange< ElementType >::All ( )
inlinestatic

Create an unbounded (open) range that contains all elements of the domain.

Returns
A new range.
See also
AtLeast, AtMost, Empty, Exclusive, GreaterThan, Inclusive, LessThan

◆ AtLeast()

template<typename ElementType >
static UE_FORCEINLINE_HINT TRange TRange< ElementType >::AtLeast ( ElementValueOrConstRef  Value)
inlinestatic

Create a left-bounded range that contains all elements greater than or equal to the specified value.

Parameters
ValueThe value.
Returns
A new range.
See also
All, AtMost, Empty, Exclusive, GreaterThan, Inclusive, LessThan

◆ AtMost()

template<typename ElementType >
static UE_FORCEINLINE_HINT TRange TRange< ElementType >::AtMost ( ElementValueOrConstRef  Value)
inlinestatic

Create a right-bounded range that contains all elements less than or equal to the specified value.

Parameters
ValueThe value.
Returns
A new range.
See also
All, AtLeast, Empty, Exclusive, GreaterThan, Inclusive, LessThan

◆ Conjoins()

template<typename ElementType >
bool TRange< ElementType >::Conjoins ( const TRange< ElementType > &  X,
const TRange< ElementType > &  Y 
) const
inline

Check whether this range conjoins the two given ranges.

A range conjoins two non-overlapping ranges if it adjoins both of them, i.e. [B, C) conjoins the two ranges [A, B) and [C, D).

Parameters
XThe first range.
YThe second range.
Returns
true if this range conjoins the two ranges, false otherwise.

◆ Contains() [1/2]

template<typename ElementType >
bool TRange< ElementType >::Contains ( const TRange< ElementType > &  Other) const
inline

Check whether this range contains another range.

Parameters
OtherThe range to check.
Returns
true if the range contains the other range, false otherwise.

◆ Contains() [2/2]

template<typename ElementType >
bool TRange< ElementType >::Contains ( ElementValueOrConstRef  Element) const
inline

Check whether this range contains the specified element.

Parameters
ElementThe element to check.
Returns
true if the range contains the element, false otherwise.

◆ Contiguous()

template<typename ElementType >
bool TRange< ElementType >::Contiguous ( const TRange< ElementType > &  Other) const
inline

Check if this range is contiguous with another range.

Two ranges are contiguous if they are adjoint or overlapping.

Parameters
OtherThe other range.
Returns
true if the ranges are contiguous, false otherwise.

◆ Difference()

template<typename ElementType >
static TArray< TRange > TRange< ElementType >::Difference ( const TRange< ElementType > &  X,
const TRange< ElementType > &  Y 
)
inlinestatic

Calculate the difference between two ranges, i.e. X - Y.

Parameters
XThe first range to subtract from.
YThe second range to subtract with.
Returns
Between 0 and 2 remaining ranges.
See also
Hull, Intersection, Union

◆ Empty()

template<typename ElementType >
static UE_FORCEINLINE_HINT TRange TRange< ElementType >::Empty ( )
inlinestatic

Return an empty range.

Returns
Empty range.
See also
All, AtLeast, AtMost, Exclusive, GreaterThan, Inclusive, LessThan

◆ Exclusive()

template<typename ElementType >
static UE_FORCEINLINE_HINT TRange TRange< ElementType >::Exclusive ( ElementValueOrConstRef  Min,
ElementValueOrConstRef  Max 
)
inlinestatic

Create a range that excludes the given minimum and maximum values.

Parameters
MinTheminimum value to be included.
MaxThe maximum value to be included.
Returns
A new range.
See also
All, AtLeast, AtMost, Empty, Exclusive, GreaterThan, Inclusive, LessThan

◆ GetLowerBound()

template<typename ElementType >
BoundsType TRange< ElementType >::GetLowerBound ( ) const
inline

Get the range's lower bound.

Returns
Lower bound.
See also
GetLowerBoundValue, GetUpperBound, HasLowerBound

◆ GetLowerBoundValue()

template<typename ElementType >
ElementValueOrConstRef TRange< ElementType >::GetLowerBoundValue ( ) const
inline

Get the value of the lower bound.

Use HasLowerBound() to ensure that this range actually has a lower bound.

Returns
Bound value.
See also
GetLowerBound, GetUpperBoundValue, HasLowerBound

◆ GetUpperBound()

template<typename ElementType >
BoundsType TRange< ElementType >::GetUpperBound ( ) const
inline

Get the range's upper bound.

Returns
Upper bound.
See also
GetLowerBound, GetUpperBoundValue, HasUpperBound

◆ GetUpperBoundValue()

template<typename ElementType >
ElementValueOrConstRef TRange< ElementType >::GetUpperBoundValue ( ) const
inline

Get the value of the upper bound.

Use HasUpperBound() to ensure that this range actually has an upper bound.

Returns
Bound value.
See also
GetLowerBoundValue, GetUpperBound, HasUpperBound

◆ GreaterThan()

template<typename ElementType >
static UE_FORCEINLINE_HINT TRange TRange< ElementType >::GreaterThan ( ElementValueOrConstRef  Value)
inlinestatic

Create a left-bounded range that contains all elements greater than the specified value.

Parameters
ValueThe value.
Returns
A new range.
See also
All, AtLeast, AtMost, Empty, Exclusive, Inclusive, LessThan

◆ HasLowerBound()

template<typename ElementType >
bool TRange< ElementType >::HasLowerBound ( ) const
inline

Check whether the range has a lower bound.

Returns
true if the range has a lower bound, false otherwise.
See also
GetLowerBound, GetLowerBoundValue, HasUpperBound

◆ HasUpperBound()

template<typename ElementType >
bool TRange< ElementType >::HasUpperBound ( ) const
inline

Check whether the range has an upper bound.

Returns
true if the range has an upper bound, false otherwise.
See also
GetUpperBound, GetUpperBoundValue, HasLowerBound

◆ Hull() [1/2]

template<typename ElementType >
static TRange TRange< ElementType >::Hull ( const TArray< TRange< ElementType > > &  Ranges)
inlinestatic

Compute the hull of many ranges.

Parameters
RangesThe ranges to hull.
Returns
The hull.
See also
Difference, Intersection, Union

◆ Hull() [2/2]

template<typename ElementType >
static TRange TRange< ElementType >::Hull ( const TRange< ElementType > &  X,
const TRange< ElementType > &  Y 
)
inlinestatic

Compute the hull of two ranges.

The hull is the smallest range that contains both ranges.

Parameters
XThe first range.
YThe second range.
Returns
The hull.
See also
Difference, Intersection, Union

◆ Inclusive()

template<typename ElementType >
static UE_FORCEINLINE_HINT TRange TRange< ElementType >::Inclusive ( ElementValueOrConstRef  Min,
ElementValueOrConstRef  Max 
)
inlinestatic

Create a range that includes the given minimum and maximum values.

Parameters
MinThe minimum value to be included.
MaxThe maximum value to be included.
Returns
A new range.
See also
All, AtLeast, AtMost, Empty, Exclusive, GreaterThan, LessThan

◆ Intersection() [1/2]

template<typename ElementType >
static TRange TRange< ElementType >::Intersection ( const TArray< TRange< ElementType > > &  Ranges)
inlinestatic

Compute the intersection of many ranges.

Parameters
RangesThe ranges to intersect.
Returns
The intersection.
See also
Difference, Hull, Union

◆ Intersection() [2/2]

template<typename ElementType >
static TRange TRange< ElementType >::Intersection ( const TRange< ElementType > &  X,
const TRange< ElementType > &  Y 
)
inlinestatic

Compute the intersection of two ranges.

The intersection of two ranges is the largest range that is contained by both ranges.

Parameters
XThe first range.
YThe second range.
Returns
The intersection, or an empty range if the ranges do not overlap.
See also
Difference, Hull, Union

◆ IsDegenerate()

template<typename ElementType >
bool TRange< ElementType >::IsDegenerate ( ) const
inline

Check whether this range is degenerate.

A range is degenerate if it contains only a single element, i.e. has the following form: [A, A]

Returns
true if the range is degenerate, false otherwise.
See also
IsEmpty

◆ IsEmpty()

template<typename ElementType >
bool TRange< ElementType >::IsEmpty ( ) const
inline

Check whether this range is empty.

A range is empty if it contains no elements, i.e. (A, A) (A, A] [A, A)

Returns
true if the range is empty, false otherwise.
See also
IsDegenerate

◆ LessThan()

template<typename ElementType >
static UE_FORCEINLINE_HINT TRange TRange< ElementType >::LessThan ( ElementValueOrConstRef  Value)
inlinestatic

Create a right-bounded range that contains all elements less than the specified value.

Parameters
ValueThe value.
Returns
A new range.
See also
All, AtLeast, AtMost, Empty, Exclusive, GreaterThan, Inclusive

◆ operator!=()

template<typename ElementType >
bool TRange< ElementType >::operator!= ( const TRange< ElementType > &  Other) const
inline

Compare this range with the specified range for inequality.

Parameters
OtherThe range to compare with.
Returns
true if the ranges are not equal, false otherwise.

◆ operator==()

template<typename ElementType >
bool TRange< ElementType >::operator== ( const TRange< ElementType > &  Other) const
inline

Compare this range with the specified range for equality.

Parameters
OtherThe range to compare with.
Returns
true if the ranges are equal, false otherwise.

◆ Overlaps()

template<typename ElementType >
bool TRange< ElementType >::Overlaps ( const TRange< ElementType > &  Other) const
inline

Check whether this range overlaps with another.

Parameters
OtherThe other range.
Returns
true if the ranges overlap, false otherwise.

◆ SetLowerBound()

template<typename ElementType >
void TRange< ElementType >::SetLowerBound ( const BoundsType NewLowerBound)
inline

Assign the new lower bound for this range

Parameters
NewLowerBoundThe new lower bound to assign
See also
GetLowerBound

◆ SetLowerBoundValue()

template<typename ElementType >
void TRange< ElementType >::SetLowerBoundValue ( ElementValueOrConstRef  NewLowerBoundValue)
inline

Assign the new lower bound value for this range. Current lower bound must not be open to call this method.

Parameters
NewLowerBoundValueThe new lower bound value to assign
See also
GetLowerBound

◆ SetUpperBound()

template<typename ElementType >
void TRange< ElementType >::SetUpperBound ( const BoundsType NewUpperBound)
inline

Assign the new upper bound for this range

Parameters
NewUpperBoundThe new upper bound to assign
See also
GetUpperBound

◆ SetUpperBoundValue()

template<typename ElementType >
void TRange< ElementType >::SetUpperBoundValue ( ElementValueOrConstRef  NewUpperBoundValue)
inline

Assign the new upper bound value for this range. Current upper bound must not be open to call this method.

Parameters
NewUpperBoundValueThe new upper bound value to assign
See also
GetUpperBound

◆ Size()

template<typename ElementType >
DifferenceType TRange< ElementType >::Size ( ) const
inline

Compute the size (diameter, length, width) of this range.

The size of a closed range is the difference between its upper and lower bound values. Use IsClosed() on the lower and upper bounds before calling this method in order to make sure that the range is closed.

Returns
Range size.

◆ Split()

template<typename ElementType >
TArray< TRange > TRange< ElementType >::Split ( ElementValueOrConstRef  Element) const
inline

Split the range into two ranges at the specified element.

If a range [A, C) does not contain the element X, the original range is returned. Otherwise the range is split into two ranges [A, X) and [X, C), each of which may be empty.

Parameters
ElementThe element at which to split the range.

◆ Union()

template<typename ElementType >
static TArray< TRange > TRange< ElementType >::Union ( const TRange< ElementType > &  X,
const TRange< ElementType > &  Y 
)
inlinestatic

Return the union of two contiguous ranges.

A union is a range or series of ranges that contains both ranges.

Parameters
XThe first range.
YThe second range.
Returns
The union, or both ranges if the two ranges are not contiguous, or no ranges if both ranges are empty.
See also
Difference, Hull, Intersection

Friends And Related Symbol Documentation

◆ GetTypeHash

template<typename ElementType >
uint32 GetTypeHash ( const TRange< ElementType > &  Range)
friend

Gets the hash for the specified range.

Parameters
RangeThe range to get the hash for.
Returns
Hash value.

◆ operator<<

template<typename ElementType >
class FArchive & operator<< ( class FArchive Ar,
TRange< ElementType > &  Range 
)
friend

Serializes the given range from or into the specified archive.

Parameters
ArThe archive to serialize from or into.
RangeThe range to serialize.
Returns
The archive.

The documentation for this class was generated from the following file: