Template Class ArrayRef#
Defined inFile ArrayRef.h
Inheritance Relationships#
Base Type#
publicHeaderOnlyArrayRef<T>
Class Documentation#
- template<typenameT>
classArrayRef:publicHeaderOnlyArrayRef<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 theArrayRef. For this reason, it is not in general safe to store anArrayRef.
This is intended to be trivially copyable, so it should be passed by value.
NOTE: We have refactored out the headeronly parts of theArrayRef 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 forArrayRef to call HeaderOnlyArrayRef methods. However, you should prefer to useArrayRef 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<typenameU>
inlineArrayRef(constSmallVectorTemplateCommon<T,U>&Vec)# Construct anArrayRef from a SmallVector.
This is templated in order to avoid instantiating SmallVectorTemplateCommon<T> whenever we copy-construct anArrayRef. NOTE: this is the only constructor that is not inherited from HeaderOnlyArrayRef.
Simple Operations, mostly inherited from HeaderOnlyArrayRef
- inlineconstexprconstT&front()const#
front - Get the first element.
We deviate from HeaderOnlyArrayRef by using TORCH_CHECK instead of STD_TORCH_CHECK
- inlineconstexprconstT&back()const#
back - Get the last element.
We deviate from HeaderOnlyArrayRef by using TORCH_CHECK instead of STD_TORCH_CHECK
Operator Overloads
- inlineconstexprconstT&at(size_tIndex)const#
Vector compatibility We deviate from HeaderOnlyArrayRef by using TORCH_CHECK instead of STD_TORCH_CHECK.
- template<typenameU>