Template Class ArrayRef

Inheritance Relationships

Derived Type

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.

Subclassed by ams::MutableArrayRef< T >

Constructors

ArrayRef() = default

Construct an empty ArrayRef.

inline 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 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.

template<typename U>
inline ArrayRef(const ArrayRef<U*> &A, std::enable_if_t<std::is_convertible<U*const*, T const*>::value>* = nullptr)

Construct an ArrayRef<const T*> from ArrayRef<T*>. This uses SFINAE to ensure that only ArrayRefs of pointers can be converted.

template<typename U, typename DummyT>
inline ArrayRef(const SmallVectorTemplateCommon<U*, DummyT> &Vec, std::enable_if_t<std::is_convertible<U*const*, T const*>::value>* = nullptr)

Construct an ArrayRef<const T*> from a SmallVector<T*>. This is templated in order to avoid instantiating SmallVectorTemplateCommon<T> whenever we copy-construct an ArrayRef.

template<typename U, typename A>
inline ArrayRef(const std::vector<U*, A> &Vec, std::enable_if_t<std::is_convertible<U*const*, T const*>::value>* = nullptr)

Construct an ArrayRef<const T*> from std::vector<T*>. This uses SFINAE to ensure that only vectors of pointers can be converted.

Simple Operations

inline iterator begin() const
inline iterator end() const
inline reverse_iterator rbegin() const
inline reverse_iterator rend() const
inline bool empty() const

empty - Check if the array is empty.

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

size - Get the array size.

inline const T &front() const

front - Get the first element.

inline const T &back() const

back - Get the last element.

template<typename Allocator>
inline MutableArrayRef<T> copy(Allocator &A)
inline bool equals(ArrayRef RHS) const

equals - Check for element-wise equality.

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

slice(n, m) - Chop off the first N elements of the array, and keep M elements in the array.

inline ArrayRef<T> slice(size_t N) const

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

inline ArrayRef<T> drop_front(size_t N = 1) const

Drop the first N elements of the array.

inline ArrayRef<T> drop_back(size_t N = 1) const

Drop the last N elements of the array.

template<class PredicateT>
inline ArrayRef<T> drop_while(PredicateT Pred) const

Return a copy of *this with the first N elements satisfying the given predicate removed.

template<class PredicateT>
inline ArrayRef<T> drop_until(PredicateT Pred) const

Return a copy of *this with the first N elements not satisfying the given predicate removed.

inline ArrayRef<T> take_front(size_t N = 1) const

Return a copy of *this with only the first N elements.

inline ArrayRef<T> take_back(size_t N = 1) const

Return a copy of *this with only the last N elements.

template<class PredicateT>
inline ArrayRef<T> take_while(PredicateT Pred) const

Return the first N elements of this Array that satisfy the given predicate.

template<class PredicateT>
inline ArrayRef<T> take_until(PredicateT Pred) const

Return the first N elements of this Array that don’t satisfy the given predicate.

Operator Overloads

inline const T &operator[](size_t Index) const
template<typename U>
std::enable_if_t<std::is_same<U, T>::value, 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<U, T>::value, 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

Conversion operators

inline operator std::vector<T>() const

Public Types

using value_type = T
using pointer = value_type*
using const_pointer = const value_type*
using reference = value_type&
using const_reference = const value_type&
using iterator = const_pointer
using const_iterator = const_pointer
using reverse_iterator = std::reverse_iterator<iterator>
using const_reverse_iterator = std::reverse_iterator<const_iterator>
using size_type = size_t
using difference_type = ptrdiff_t