ArrayRef

#include <gccs/ArrayRef.hpp>
template<class T>
class ArrayRef

A non-owning, immutable view on some contiguous data. It only holds a pointer and the size of the data.

Public Types

using value_type = T
using reference = T&
using const_reference = const T&
using difference_type = std::ptrdiff_t
using size_type = std::size_t
using iterator = T*
using const_iterator = const T*

Public Functions

constexpr ArrayRef() = default
inline constexpr ArrayRef(T *p, std::size_t size) noexcept
template<class U>
inline constexpr ArrayRef(std::initializer_list<U> ilist)

Constructs a view from an initializer_list This is necessary to resolve brace-enclosed initializer lists This function only participates in overload resolution if ilist.begin() is convertible to T*.

template<class U>
inline constexpr ArrayRef(U &t)

Constructs a view to a container’s underlying array.

This overload only participates in overload resolution if the container declares data() and size() member functions or is a C-style array.

template<class U>
inline constexpr ArrayRef(const U &t)

Constructs a view to a container’s underlying array.

This overload only partiipates in overload resolution if the container declares data() and size() member functions or is a C-style array, and the pointer returned by either data() or array decay is implicitly convertible to T* (i.e. we allow non-const to const conversion).

inline constexpr T *data() const noexcept

Direct access to the underlying array.

inline constexpr std::size_t size() const noexcept

Returns the number of elements.

inline constexpr bool empty() const noexcept

Checks whether the container is empty.

inline T &front() noexcept

Access the first element.

ArrayRef must not be empty before calling this function.

inline const T &front() const noexcept

Access the first element.

ArrayRef must not be empty before calling this function.

inline T &back() noexcept

Access the last element.

ArrayRef must not be empty before calling this function.

inline const T &back() const noexcept

Access the last element.

ArrayRef must not be empty before calling this function.

inline T &operator[](std::size_t i) const noexcept

Access specified element.

inline iterator begin() const noexcept

Returns an iterator to the beginning.

inline const_iterator cbegin() const noexcept

Returns a const iterator to the beginning.

inline iterator end() const noexcept

Returns an iterator to the end.

inline const_iterator cend() const noexcept

Returns a const iterator to the end.

inline std::size_t max_size() const noexcept

Returns the maximum number of elements that can be stored.

template<class T>
class ArrayRef<const T>

Specialization for T const.

Subclassed by poplar::ArrayRef< T >

Public Types

using value_type = const T
using reference = const T&
using const_reference = const T&
using difference_type = std::ptrdiff_t
using size_type = std::size_t
using iterator = const T*
using const_iterator = const T*

Public Functions

ArrayRef(std::nullptr_t) = delete
inline constexpr ArrayRef()

Constructs a view that is empty.

inline constexpr ArrayRef(const T *p, std::size_t size)

Constructs a view to a buffer given its starting address and size.

template<class U, class Alloc>
inline ArrayRef(const std::vector<U, Alloc> &v)

Construct a view to a vector storage.

If vector elements are pointers this constructor only participates in overload resolution if we can convert the vector elements to T

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

Construct a view from a std::array.

template<std::size_t N>
inline constexpr ArrayRef(const T (&p)[N])

Construct a view from a C-style array.

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

Constructs a view from an initializer_list.

template<class U>
inline constexpr ArrayRef(const ArrayRef<U> &a)

Construct a view to an ArrayRef storage.

This constructor only participates in overload resolution if we can convert the ArrayRef elements to T

inline constexpr const T *data() const

Direct access to the underlying array.

inline constexpr std::size_t size() const

Returns the number of elements.

inline constexpr bool empty() const

Checks whether the container is empty.

inline const T &front() const

Access the first element.

ArrayRef must not be empty before calling this function.

inline const T &back() const

Access the last element.

ArrayRef must not be empty before calling this function.

inline const T &operator[](std::size_t i) const

Access specified element.

inline const_iterator begin() const

Returns a const iterator to the beginning.

inline const_iterator cbegin() const

Returns a const iterator to the end.

inline const_iterator end() const

Returns a const iterator to the end.

inline const_iterator cend() const

Returns a const iterator to the end.

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

Returns a copy of underlying data as a std:vector<T>

inline std::size_t max_size() const

Returns the maximum number of elements that can be stored.

The following API is deprecated and may be removed in future.

#include <poplar/ArrayRef.hpp>
template<class T>
class ArrayRef : public gccs::ArrayRef<const T>

Deprecated:

Use gccs::ArrayRef<T>