sincerely Singaporean

If you have not done so, read this full tutorial on how to use SGEXTN to build an application.

SGLSpan

see header file

(no source file, everything inside header)

template ‹typename T› class SGLSpan;

part of SGEXTN module SG_Containers

span for any type of data

detailed description

list of all including inherited members

implementation details

preprocessor file inclusion directive: #include ‹SGLSpan.h›

CMake target for BuildLah: SGEXTN::SG_Containers

see this link for more information about BuildLah

parent class: (none)

children classes: (none)

instance member functions

SGLSpan(T* dataInternal, int lengthInternal);

[[nodiscard]] const T& at(int i) const;

[[nodiscard]] T& at(int i);

[[nodiscard]] int length() const;

[[nodiscard]] const T* pointerToData(int n) const;

[[nodiscard]] T* pointerToData(int n);

[[nodiscard]] SGLSpan subspan(int start, int length) const;

[[nodiscard]] SGLSpan subspanLeft(int length) const;

[[nodiscard]] SGLSpan subspanRight(int length) const;

Detailed Description

SGLSpan provides a template based span that can be used with any data type. SGLSpan does not own the data that it allows access to. Deleting heap data accessed through SGLSpan is undefined behaviour in the form of double delete. This is a template based class with no separate source file.

Implementation Details

SGLSpan stores a pointer to the start of the span and the number of elements in the span.

SGLSpan(T* dataInternal, int lengthInternal);

Creates a SGLSpan starting from dataInternal with a length of lengthInternal.

Negative lengthInternal will cause a crash.

dataInternal being nullptr will cause a crash.

If any memory between dataInternal (inclusive) and dataInternal + lengthInternal (exclusive) is not allocated, have been deleted, or if the 2 endpoints come from different data structures, creating the span is undefined behaviour.

Using the span in any way after the host data structure is deleted is undefined behaviour

To avoid undefined behaviour, do not allocate any SGLSpan on the heap.

[[nodiscard]] const T& at(int i) const;

Returns a constant reference to the element at index i of the SGLSpan.

If i is out of bounds, this causes a crash.

[[nodiscard]] T& at(int i);

Returns a reference to the element at index i of the SGLSpan.

This returns a reference and not a copy. Assigning to the returned value (using it as a lvalue) modifies the host data structure.

If i is out of bounds, this causes a crash.

[[nodiscard]] int length() const;

Returns the length of the SGLSpan.

This is constant after the creation of the SGLSpan.

[[nodiscard]] const T* pointerToData(int n) const;

Returns a read only pointer to the element at index n of the original span.

It is ok for n to be out of bounds as long as the returned pointer is not dereferenced. This can be done intentionally to define bounds for SGLSort.

The returned value may function as an iterator.

Dereferencing the returned pointer when n is out of bounds is undefined behaviour.

[[nodiscard]] T* pointerToData(int n);

Returns a pointer to the element at index n of the original span.

It is ok for n to be out of bounds as long as the returned pointer is not dereferenced. This can be done intentionally to define bounds for SGLSort.

The returned value may function as an iterator.

Dereferencing the returned pointer when n is out of bounds is undefined behaviour.

[[nodiscard]] SGLSpan subspan(int start, int length) const;

Returns a subspan starting at index start of the original span with a length of length.

Negative length will crash.

If start or start + length - 1 is out of bounds, this will crash.

[[nodiscard]] SGLSpan subspanLeft(int length) const;

Returns a subspan containing the first length elements of the original span.

Negative length will crash.

If length is greater than the length of the span, this will crash.

[[nodiscard]] SGLSpan subspanRight(int length) const;

Returns a subspan containing the last length elements of the original span.

Negative length will crash.

If length is greater than the length of the span, this will crash.

©2025 05524F.sg (Singapore)

contact 05524F / report a bug / make a suggestion

about 05524F SINGAPORE values

list of 05524F projects