Navigation
API > API/Runtime > API/Runtime/Core
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.
| Name | TRange |
| Type | class |
| Header File | /Engine/Source/Runtime/Core/Public/Math/Range.h |
| Include Path | #include "Math/Range.h" |
Syntax
template<typename ElementType>
class TRange
Derived Classes
TRange derived class hierarchy
Constructors
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
TRange
(
ElementValueOrConstRef A, |
Create and initializes a new range with the given lower and upper bounds. | Math/Range.h | |
TRange () |
Default constructor (no initialization). | Math/Range.h | |
TRange
(
ElementValueOrConstRef A |
Create a range with a single element.The created range is of the form [A, A]. | Math/Range.h | |
TRange
(
const BoundsType& InLowerBound, |
Create and initializes a new range with the given lower and upper bounds. | Math/Range.h |
Typedefs
| Name | Type | Remarks | Include Path |
|---|---|---|---|
| BoundsType | TRangeBound< ElementType > | Math/Range.h | |
| ElementValueOrConstRef | TCallTraits< ElementType >::ParamType | Math/Range.h |
Variables
Protected
| Name | Type | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|---|
| LowerBound | BoundsType | Holds the range's lower bound. | Math/Range.h | |
| UpperBound | BoundsType | Holds the range's upper bound. | Math/Range.h |
Functions
Public
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
| Check whether this range adjoins to another. | Math/Range.h | ||
| Check whether this range conjoins the two given ranges. | Math/Range.h | ||
| Check whether this range contains another range. | Math/Range.h | ||
bool Contains
(
ElementValueOrConstRef Element |
Check whether this range contains the specified element. | Math/Range.h | |
bool Contiguous
(
const TRange& Other |
Check if this range is contiguous with another range. | Math/Range.h | |
BoundsType GetLowerBound () |
Get the range's lower bound. | Math/Range.h | |
ElementValueOrConstRef GetLowerBoundValue () |
Get the value of the lower bound. | Math/Range.h | |
BoundsType GetUpperBound () |
Get the range's upper bound. | Math/Range.h | |
ElementValueOrConstRef GetUpperBoundValue () |
Get the value of the upper bound. | Math/Range.h | |
bool HasLowerBound () |
Check whether the range has a lower bound. | Math/Range.h | |
bool HasUpperBound () |
Check whether the range has an upper bound. | Math/Range.h | |
bool IsDegenerate () |
Check whether this range is degenerate. | Math/Range.h | |
bool IsEmpty () |
Check whether this range is empty. | Math/Range.h | |
bool Overlaps
(
const TRange& Other |
Check whether this range overlaps with another. | Math/Range.h | |
void SetLowerBound
(
const BoundsType& NewLowerBound |
Assign the new lower bound for this range | Math/Range.h | |
void SetLowerBoundValue
(
ElementValueOrConstRef NewLowerBoundValue |
Assign the new lower bound value for this range. | Math/Range.h | |
void SetUpperBound
(
const BoundsType& NewUpperBound |
Assign the new upper bound for this range | Math/Range.h | |
void SetUpperBoundValue
(
ElementValueOrConstRef NewUpperBoundValue |
Assign the new upper bound value for this range. | Math/Range.h | |
DifferenceType Size () |
Compute the size (diameter, length, width) of this range. | Math/Range.h | |
| Split the range into two ranges at the specified element. | Math/Range.h |
Static
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
| Create an unbounded (open) range that contains all elements of the domain. | Math/Range.h | ||
| Create a left-bounded range that contains all elements greater than or equal to the specified value. | Math/Range.h | ||
| Create a right-bounded range that contains all elements less than or equal to the specified value. | Math/Range.h | ||
static TArray< TRange > Difference
(
const TRange& X, |
Calculate the difference between two ranges, i.e. X - Y. | Math/Range.h | |
| Return an empty range. | Math/Range.h | ||
| Create a range that excludes the given minimum and maximum values. | Math/Range.h | ||
static TRange GreaterThan
(
ElementValueOrConstRef Value |
Create a left-bounded range that contains all elements greater than the specified value. | Math/Range.h | |
| Compute the hull of two ranges.The hull is the smallest range that contains both ranges. | Math/Range.h | ||
| Compute the hull of many ranges. | Math/Range.h | ||
| Create a range that includes the given minimum and maximum values. | Math/Range.h | ||
static TRange Intersection
(
const TRange& X, |
Compute the intersection of two ranges. | Math/Range.h | |
static TRange Intersection
(
const TArray< TRange >& Ranges |
Compute the intersection of many ranges. | Math/Range.h | |
| Create a right-bounded range that contains all elements less than the specified value. | Math/Range.h | ||
| Return the union of two contiguous ranges. | Math/Range.h |
Operators
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
bool operator!=
(
const TRange& Other |
Compare this range with the specified range for inequality. | Math/Range.h | |
bool operator==
(
const TRange& Other |
Compare this range with the specified range for equality. | Math/Range.h |
See Also
-
RangeBound