Utility

template<typename T>
struct ttor::view

A non-owning view of a memory buffer.

A view if a pair (buffer, size) representing a view of a memory buffer. The view does not take ownership of the buffer; the user is responsible for the buffer to be valid anytime it is used through the view. A view’s pointer should always be aligned (so that T *start can be dereferenced).

Public Functions

view(T *start, size_t size)

Creates a view.

Pre

size >= 0

Pre

if size > 0, start is a valid pointer of type T* and can be dereferenced.

Parameters
  • [in] start: A pointer to the start of the buffer of element T. start should be aligned, so that T *start is valid (unless size = 0).

  • [in] size: The number of element of type T in the buffer.

view()

Creates an empty view.

T *begin() const

The start of the view.

Return

A pointer to the start of the view.

Post

begin() + i for 0 <= i < size() are all valid addresses for elements of type T.

T *end() const

The past-the-end of the view.

Return

A pointer to the past-the-end of the view.

T *data() const

The start of the view.

Return

A pointer to the start of the view.

Post

data() + i for 0 <= i < size() are all valid addresses for elements of type T.

size_t size() const

The size of the view.

Return

The number of elements (of type T) of the view.

bool operator==(const view<T> &rhs) const

Test views for equality.

Return

true if both views refer to the same memory buffers with the same number of elements; false otherwise.