WPILibC++  2019.3.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
wpi::ArrayRef< T > Class Template Reference

ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory), i.e. More...

#include <ArrayRef.h>

Inheritance diagram for wpi::ArrayRef< T >:
wpi::MutableArrayRef< T > wpi::OwningArrayRef< T >

Public Types

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

Public Member Functions

Constructors
 ArrayRef ()=default
 Construct an empty ArrayRef.
 
 ArrayRef (nullopt_t)
 Construct an empty ArrayRef from nullopt.
 
 ArrayRef (const T &OneElt)
 Construct an ArrayRef from a single element.
 
 ArrayRef (const T *data, size_t length)
 Construct an ArrayRef from a pointer and length.
 
 ArrayRef (const T *begin, const T *end)
 Construct an ArrayRef from a range.
 
template<typename U >
 ArrayRef (const SmallVectorTemplateCommon< T, U > &Vec)
 Construct an ArrayRef from a SmallVector. More...
 
template<typename A >
 ArrayRef (const std::vector< T, A > &Vec)
 Construct an ArrayRef from a std::vector.
 
template<size_t N>
constexpr ArrayRef (const std::array< T, N > &Arr)
 Construct an ArrayRef from a std::array.
 
template<size_t N>
constexpr ArrayRef (const T(&Arr)[N])
 Construct an ArrayRef from a C array.
 
 ArrayRef (const std::initializer_list< T > &Vec)
 Construct an ArrayRef from a std::initializer_list.
 
template<typename U >
 ArrayRef (const ArrayRef< U * > &A, typename std::enable_if< std::is_convertible< U *const *, T const * >::value >::type *=nullptr)
 Construct an ArrayRef<const T*> from ArrayRef<T*>. More...
 
template<typename U , typename DummyT >
 ArrayRef (const SmallVectorTemplateCommon< U *, DummyT > &Vec, typename std::enable_if< std::is_convertible< U *const *, T const * >::value >::type *=nullptr)
 Construct an ArrayRef<const T*> from a SmallVector<T*>. More...
 
template<typename U , typename A >
 ArrayRef (const std::vector< U *, A > &Vec, typename std::enable_if< std::is_convertible< U *const *, T const * >::value >::type *=0)
 Construct an ArrayRef<const T*> from std::vector<T*>. More...
 
Simple Operations
iterator begin () const
 
iterator end () const
 
reverse_iterator rbegin () const
 
reverse_iterator rend () const
 
bool empty () const
 empty - Check if the array is empty.
 
const T * data () const
 
size_t size () const
 size - Get the array size.
 
const T & front () const
 front - Get the first element.
 
const T & back () const
 back - Get the last element.
 
template<typename Allocator >
ArrayRef< T > copy (Allocator &A)
 
bool equals (ArrayRef RHS) const
 equals - Check for element-wise equality.
 
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. More...
 
ArrayRef< T > slice (size_t N) const
 slice(n) - Chop off the first N elements of the array.
 
ArrayRef< T > drop_front (size_t N=1) const
 Drop the first N elements of the array.
 
ArrayRef< T > drop_back (size_t N=1) const
 Drop the last N elements of the array.
 
template<class PredicateT >
ArrayRef< T > drop_while (PredicateT Pred) const
 Return a copy of *this with the first N elements satisfying the given predicate removed. More...
 
template<class PredicateT >
ArrayRef< T > drop_until (PredicateT Pred) const
 Return a copy of *this with the first N elements not satisfying the given predicate removed. More...
 
ArrayRef< T > take_front (size_t N=1) const
 Return a copy of *this with only the first N elements.
 
ArrayRef< T > take_back (size_t N=1) const
 Return a copy of *this with only the last N elements.
 
template<class PredicateT >
ArrayRef< T > take_while (PredicateT Pred) const
 Return the first N elements of this Array that satisfy the given predicate. More...
 
template<class PredicateT >
ArrayRef< T > take_until (PredicateT Pred) const
 Return the first N elements of this Array that don't satisfy the given predicate. More...
 
Operator Overloads
const T & operator[] (size_t Index) const
 
template<typename U >
std::enable_if< std::is_same
< U, T >::value, ArrayRef< T >
>::type & 
operator= (U &&Temporary)=delete
 Disallow accidental assignment from a temporary. More...
 
template<typename U >
std::enable_if< std::is_same
< U, T >::value, ArrayRef< T >
>::type & 
operator= (std::initializer_list< U >)=delete
 Disallow accidental assignment from a temporary. More...
 
Expensive Operations
std::vector< T > vec () const
 
Conversion operators
 operator std::vector< T > () const
 

Detailed Description

template<typename T>
class wpi::ArrayRef< 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.

Constructor & Destructor Documentation

template<typename T>
template<typename U >
wpi::ArrayRef< T >::ArrayRef ( const SmallVectorTemplateCommon< T, U > &  Vec)
inline

Construct an ArrayRef from a SmallVector.

This is templated in order to avoid instantiating SmallVectorTemplateCommon<T> whenever we copy-construct an ArrayRef.

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

Construct an ArrayRef<const T*> from ArrayRef<T*>.

This uses SFINAE to ensure that only ArrayRefs of pointers can be converted.

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

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 T>
template<typename U , typename A >
wpi::ArrayRef< T >::ArrayRef ( const std::vector< U *, A > &  Vec,
typename std::enable_if< std::is_convertible< U *const *, T const * >::value >::type *  = 0 
)
inline

Construct an ArrayRef<const T*> from std::vector<T*>.

This uses SFINAE to ensure that only vectors of pointers can be converted.

Member Function Documentation

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

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

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

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

template<typename T>
template<typename U >
std::enable_if<std::is_same<U, T>::value, ArrayRef<T> >::type& wpi::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 T>
template<typename U >
std::enable_if<std::is_same<U, T>::value, ArrayRef<T> >::type& wpi::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.

template<typename T>
ArrayRef<T> wpi::ArrayRef< T >::slice ( size_t  N,
size_t  M 
) const
inline

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

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

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

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

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


The documentation for this class was generated from the following file: