MemSpan

    MemSpan is a view on a contiguous section of writeable memory. A view does not own the memory and neither allocates nor de-allocates. The memory in the view is always owned by some other container and it is the responsibility of the code to make sure the lifetime of the view is no more than that of the owning container .

    A MemSpan is generally constructed on either an array or an allocated buffer. This allows the buffer to be passed around with intrinsic length information. The buffer can also be treated as an array of varying types, which makes working with serialized data much easier.

    class MemSpan

    A span of writable memory. Because this is a chunk of memory, conceptually delimited by start and end pointers, the sizing type is ptrdiff_t so that all of the sizing is consistent with differences between pointers. The memory is owned by some other object and that object must maintain the memory as long as the span references it.

    • void *() const

    • size() const

      Return the size of the span.

    • bool operator==(MemSpan const &that) const

      Check the equality of two spans, which are equal if they contain the same number of bytes of the same values.

    • template<typename V>
      at(ptrdiff_t n) const

    • template<typename >
      *ptr(ptrdiff_t n) const

      Return a pointer to a value of type V as if the span were are array of type V.

    • prefix(ptrdiff_t n) const

      Return a new instance that contains the first n bytes of the current span. If n is larger than the number of bytes in the span, only that many bytes are returned.

    Footnotes