Rate this Page

Template Class ArrayRef#

Page Contents

Class Documentation#

template<typename T>
class ArrayRef#

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.

Constructors

inline constexpr ArrayRef()#

Construct an empty ArrayRef.

inline constexpr ArrayRef(const T &OneElt)#

Construct an ArrayRef from a single element.

inline constexpr ArrayRef(const T *data, size_t length)#

Construct an ArrayRef from a pointer and length.

inline constexpr ArrayRef(const T *begin, const T *end)#

Construct an ArrayRef from a range.

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.

template<typename Container, typename U = decltype(std::declval<Container>().data()), typename = std::enable_if_t<(std::is_same_v<U, T*> || std::is_same_v<U, T const*>)>>
inline ArrayRef(const Container &container)#
template<typename A>
inline ArrayRef(const std::vector<T, A> &Vec)#

Construct an ArrayRef from a std::vector.

template<size_t N>
inline constexpr ArrayRef(const std::array<T, N> &Arr)#

Construct an ArrayRef from a std::array.

template<size_t N>
inline constexpr ArrayRef(const T (&Arr)[N])#

Construct an ArrayRef from a C array.

inline constexpr ArrayRef(const std::initializer_list<T> &Vec)#

Construct an ArrayRef from a std::initializer_list.

Simple Operations

inline constexpr iterator begin() const#
inline constexpr iterator end() const#
inline constexpr const_iterator cbegin() const#
inline constexpr const_iterator cend() const#
inline constexpr reverse_iterator rbegin() const#
inline constexpr reverse_iterator rend() const#
inline constexpr bool allMatch(const std::function<bool(const T&)> &pred) const#

Check if all elements in the array satisfy the given expression.

inline constexpr bool empty() const#

empty - Check if the array is empty.

inline constexpr const T *data() const#
inline constexpr size_t size() const#

size - Get the array size.

inline constexpr const T &front() const#

front - Get the first element.

inline constexpr const T &back() const#

back - Get the last element.

inline constexpr bool equals(ArrayRef RHS) const#

equals - Check for element-wise equality.

inline constexpr ArrayRef<T> slice(size_t N, size_t M) const#

slice(n, m) - Take M elements of the array starting at element N

inline constexpr ArrayRef<T> slice(size_t N) const#

slice(n) - Chop off the first N elements of the array.

Operator Overloads

inline constexpr const T &operator[](size_t Index) const#
inline constexpr const T &at(size_t Index) const#

Vector compatibility.

template<typename U>
std::enable_if_t<std::is_same_v<U, T>, ArrayRef<T>> &operator=(U &&Temporary) = delete#

Disallow accidental assignment from a temporary.

The declaration here is extra complicated so that “arrayRef = {}” continues to select the move assignment operator.

template<typename U>
std::enable_if_t<std::is_same_v<U, T>, ArrayRef<T>> &operator=(std::initializer_list<U>) = delete#

Disallow accidental assignment from a temporary.

The declaration here is extra complicated so that “arrayRef = {}” continues to select the move assignment operator.

Expensive Operations

inline std::vector<T> vec() const#

Public Types

using iterator = const T*#
using const_iterator = const T*#
using size_type = size_t#
using value_type = T#
using reverse_iterator = std::reverse_iterator<iterator>#