simple_span#

namespace std_#

Namespace that provides lightweight standard-library-like utilities.

template<typename T>
class span#
#include <simple_span.h>

Lightweight non-owning view over a contiguous sequence of elements.

Provides a subset of the C++20 std::span interface without depending on C++20. The span does not own the underlying storage; the caller is responsible for ensuring the pointed-to data remains valid for the lifetime of the span.

Template Parameters:

T – Element type of the sequence.

Public Functions

inline span(T *data, std::size_t size)#

Constructs a span from a pointer and an element count.

Parameters:
  • data – Pointer to the first element of the sequence.

  • size – Number of elements in the sequence.

inline T *data() const#

Returns a pointer to the first element of the sequence.

inline std::size_t size() const#

Returns the number of elements in the sequence.

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

Returns a reference to the element at the given index.

Parameters:

index – Zero-based position of the element to access.

Returns:

Reference to the element at index.

inline T *begin() const#

Returns a pointer to the first element, suitable for range-based iteration.

inline T *end() const#

Returns a pointer one past the last element, suitable for range-based iteration.

Private Members

T *data_#

Pointer to the first element of the viewed sequence.

std::size_t size_#

Number of elements in the viewed sequence.