Template Class ArrayRef#
Defined in File ArrayRef.h
Page Contents
Class Documentation#
-
template<typename T>
class ArrayRef : public HeaderOnlyArrayRef<T># ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory), i.e.
a start pointer and a length. It allows various APIs to take consecutive elements easily and conveniently.
This class does not own the underlying data, it is expected to be used in situations where the data resides in some other buffer, whose lifetime extends past that of the ArrayRef. For this reason, it is not in general safe to store an ArrayRef.
This is intended to be trivially copyable, so it should be passed by value.
NOTE: We have refactored out the headeronly parts of the ArrayRef struct into HeaderOnlyArrayRef. As adding
virtualwould change the performance of the underlying constexpr calls, we rely on apparent-type dispatch for inheritance. This should be fine because their memory format is the same, and it is never incorrect for ArrayRef to call HeaderOnlyArrayRef methods. However, you should prefer to use ArrayRef when possible, because its use of TORCH_CHECK will lead to better user-facing error messages.Constructors, all inherited from HeaderOnlyArrayRef except for
SmallVector.
As inherited constructors won’t work with class template argument deduction (CTAD) until C++23, we add deduction guides after the class definition to enable CTAD.
-
template<typename U>
inline ArrayRef(const SmallVectorTemplateCommon<T, U> &Vec)# Construct an ArrayRef from a SmallVector.
This is templated in order to avoid instantiating SmallVectorTemplateCommon<T> whenever we copy-construct an ArrayRef. NOTE: this is the only constructor that is not inherited from HeaderOnlyArrayRef.
Simple Operations, mostly inherited from HeaderOnlyArrayRef
-
inline constexpr const T &front() const#
front - Get the first element.
We deviate from HeaderOnlyArrayRef by using TORCH_CHECK instead of STD_TORCH_CHECK
-
inline constexpr const T &back() const#
back - Get the last element.
We deviate from HeaderOnlyArrayRef by using TORCH_CHECK instead of STD_TORCH_CHECK
Operator Overloads
-
inline constexpr const T &at(size_t Index) const#
Vector compatibility We deviate from HeaderOnlyArrayRef by using TORCH_CHECK instead of STD_TORCH_CHECK.
-
template<typename U>