logo

Programming Languages - Slices

Go

// a is an array
a := [3]int{1, 2, 3}

// s is a slice, notice that there's no length specified.
s := []int{1, 2, 3}

Rust

Slice reference: &[T].

E.g.

// Using array
fn min(arr: &[i32; 8], start: usize, count: usize) -> i32 {
    //...
}

// Using slice, notice that there's no length specified.
fn min(arr: &[i32]) -> i32 {
    //...
}

C++

Use absl::Span: https://abseil.io/tips/93

Span<const T> is to std::vector<T> what string_view is to string.