immutable array of size()
elements of type T. The storage for the array is not owned by the array_ref
object, and clients must arrange for the backing store to remain live while the array_ref
object is in use.
Implicit conversion operations are provided from types with contiguous iterators like std::vector
, std::string
, std::array
, and primitive arrays. array_ref
objects are invalidated by any operation that invalidates their underlying pointers.
One common use for array_ref
is when passing arguments to a routine where you want to be able to accept a variety of array types. The usual approach here is to have the client explicitly pass in a pointer and a length, as in:
array_ref
as the argument to the routine: array_ref
classes make the view const. It may be useful to extend that to allow modifications of the referenced array elements, and use array_ref<const T>
for immutable views.