---
title: "ClikaRT::Span"
sidebar_label: "Span"
description: "A non-owning view over size() contiguous elements of T, the C++17 stand-in for std::span (see the file note above)."
---

<!-- Generated by tools/doxygen2mdx from Doxygen XML. Do not edit. -->

<span class="api-kind api-kind--class">class</span>

**Header:** `ClikaRT/common/span.h`  
**Template:** `template <``class T``>`

[`ClikaRT::Span`](./Span.md)`<T>`: a minimal, **C++17-compatible** contiguous view, the public stand-in for `std::span` (which is C++20). The public API uses it so a consumer can build against C++17 (`std::string_view` / `std::optional` are already C++17). `T` carries const-ness: `Span<const X>` is a read-only view, `Span<X>` a mutable one, matching the `std::span<const X>` / `std::span<X>` the API used before.

At C++20+ it interconverts with `std::span` for zero-friction interop; a C++17 consumer sees only `Span`.

A non-owning view over [`size()`](./Span.md#size) contiguous elements of `T`, the C++17 stand-in for `std::span` (see the file note above). It never allocates, copies, or owns: the viewed memory must outlive every copy of the view. `T`'s constness is the access law: [`Span`](./Span.md)`<const X>` reads, [`Span`](./Span.md)`<X>` writes through to the caller's memory.

## Types

### using element\_type {#element_type}

<div class="api-signature">

`using` **`element_type`** `=` `T`

</div>

the viewed element type, constness included.

<div class="api-declared">

Declared in `ClikaRT/common/span.h`, line 32

</div>

### using value\_type {#value_type}

<div class="api-signature">

`using` **`value_type`** `=` `std::remove_cv_t<T>`

</div>

[`element_type`](./Span.md#element_type) with cv stripped.

<div class="api-declared">

Declared in `ClikaRT/common/span.h`, line 33

</div>

### using size\_type {#size_type}

<div class="api-signature">

`using` **`size_type`** `=` `std::size_t`

</div>

the size / index type.

<div class="api-declared">

Declared in `ClikaRT/common/span.h`, line 34

</div>

### using pointer {#pointer}

<div class="api-signature">

`using` **`pointer`** `=` `T*`

</div>

raw pointer into the viewed memory.

<div class="api-declared">

Declared in `ClikaRT/common/span.h`, line 35

</div>

### using reference {#reference}

<div class="api-signature">

`using` **`reference`** `=` `T&`

</div>

reference into the viewed memory.

<div class="api-declared">

Declared in `ClikaRT/common/span.h`, line 36

</div>

### using iterator {#iterator}

<div class="api-signature">

`using` **`iterator`** `=` `T*`

</div>

iterators are raw pointers.

<div class="api-declared">

Declared in `ClikaRT/common/span.h`, line 37

</div>

## Member functions

### Span() {#Span}

<div class="api-signature">

`constexpr` `constexpr` **`Span`**() `noexcept`

</div>

An empty view: [`data()`](./Span.md#data)` == nullptr`, [`size()`](./Span.md#size)` == 0`.

<div class="api-declared">

Declared in `ClikaRT/common/span.h`, line 40

</div>

### Span(T, size\_type) {#Span-2}

<div class="api-signature">

`constexpr` `constexpr` **`Span`**(`T*` `data`, [`size_type`](./Span.md#size_type) `size`) `noexcept`

</div>

View [`size`](./Span.md#size) elements starting at [`data`](./Span.md#data); not copied, and the memory must outlive the view.

<div class="api-declared">

Declared in `ClikaRT/common/span.h`, line 42

</div>

### Span(T, T) {#Span-3}

<div class="api-signature">

`constexpr` `constexpr` **`Span`**(`T*` `first`, `T*` `last`) `noexcept`

</div>

View the half-open range `[first, last)`; not copied.

<div class="api-declared">

Declared in `ClikaRT/common/span.h`, line 44

</div>

### Span(T(\&)) {#Span-4}

<div class="api-signature">

`template <``std::size_t` `N``>`<br />`constexpr` `constexpr` **`Span`**(`T(&)` `arr``[N]`) `noexcept`

</div>

From a C array.

<div class="api-declared">

Declared in `ClikaRT/common/span.h`, line 49

</div>

### Span(initializer\_list\<value\_type\>) {#Span-5}

<div class="api-signature">

`template <``class U` `=` `T`, `class` `=` `std::enable_if_t<std::is_const_v<U>>``>`<br />`constexpr` `constexpr` **`Span`**(`std::initializer_list<`[`value_type`](./Span.md#value_type)`>` `il`) `noexcept`

</div>

From a braced list at the call site; see the lifetime note above (never store the result).

From a braced initializer list; enables `f(t, {1, 5, N, K})` directly at the call site (the list's backing array lives through the full call expression). Only for a read-only [`Span`](./Span.md)`<const T>`. Like `c10::ArrayRef`, do NOT store the resulting [Span](./Span.md): the backing array dies at the end of the statement, so a stored view would dangle; pass it straight as an argument.

The `-Winit-list-lifetime` suppression is intentional: [Span](./Span.md) is a non-owning view by contract, and the caller guarantees the backing array outlives the surrounding full-expression (the call-argument idiom above). GCC-only guard: clang has no such warning group and emits no diagnostic for this pattern.

<div class="api-declared">

Declared in `ClikaRT/common/span.h`, line 68

</div>

### Span(C) {#Span-6}

<div class="api-signature">

`template <``class C``>`<br />`constexpr` `constexpr` **`Span`**(`C&&` `c`)

</div>

From any contiguous container with `.`[`data()`](./Span.md#data) / `.`[`size()`](./Span.md#size) (std::vector, std::array, …), const-ness permitting (a [`Span`](./Span.md)`<const X>` accepts a container of `X`; a [`Span`](./Span.md)`<X>` rejects a const container). Not [`Span`](./Span.md) itself.

<div class="api-declared">

Declared in `ClikaRT/common/span.h`, line 83

</div>

### Span(Span\<U\>) {#Span-7}

<div class="api-signature">

`template <``class U`, `class` `=` `std::enable_if_t<!std::is_same<U, T>::value && std::is_convertible<U (*)[], T (*)[]>::value>``>`<br />`constexpr` `constexpr` **`Span`**(`const Span<U>&` `other`) `noexcept`

</div>

[`Span`](./Span.md)`<X>` → [`Span`](./Span.md)`<const X>` (const-adding); the same-type copy is the implicit copy constructor.

<div class="api-declared">

Declared in `ClikaRT/common/span.h`, line 91

</div>

### data() {#data}

<div class="api-signature">

`constexpr` `T*` **`data`**() `const noexcept`

</div>

Pointer to the first viewed element (`nullptr` when empty).

<div class="api-declared">

Declared in `ClikaRT/common/span.h`, line 101

</div>

### size() {#size}

<div class="api-signature">

`constexpr` [`size_type`](./Span.md#size_type) **`size`**() `const noexcept`

</div>

Number of viewed elements.

<div class="api-declared">

Declared in `ClikaRT/common/span.h`, line 103

</div>

### empty() {#empty}

<div class="api-signature">

`constexpr` `bool` **`empty`**() `const noexcept`

</div>

True when [`size()`](./Span.md#size)` == 0`.

<div class="api-declared">

Declared in `ClikaRT/common/span.h`, line 105

</div>

### operator\[\]() {#operator-subscript}

<div class="api-signature">

`constexpr` `T&` **`operator[]`**([`size_type`](./Span.md#size_type) `i`) `const`

</div>

The element at `i`; no bounds check.

<div class="api-declared">

Declared in `ClikaRT/common/span.h`, line 107

</div>

### front() {#front}

<div class="api-signature">

`constexpr` `T&` **`front`**() `const`

</div>

The first element; undefined on an empty view.

<div class="api-declared">

Declared in `ClikaRT/common/span.h`, line 109

</div>

### back() {#back}

<div class="api-signature">

`constexpr` `T&` **`back`**() `const`

</div>

The last element; undefined on an empty view.

<div class="api-declared">

Declared in `ClikaRT/common/span.h`, line 111

</div>

### begin() {#begin}

<div class="api-signature">

`constexpr` [`iterator`](./Span.md#iterator) **`begin`**() `const noexcept`

</div>

Iterator at the first element (a raw pointer).

<div class="api-declared">

Declared in `ClikaRT/common/span.h`, line 113

</div>

### end() {#end}

<div class="api-signature">

`constexpr` [`iterator`](./Span.md#iterator) **`end`**() `const noexcept`

</div>

Iterator one past the last element.

<div class="api-declared">

Declared in `ClikaRT/common/span.h`, line 115

</div>
