Half the functions in the project take const std::vector<int>&, the other half take (const int*, size_t), with an eternal customs checkpoint of copies between them. The new tech lead looked at it, sighed, and filed 'we need a span' into tech debt. The tech debt got assigned to you. Write the non-owning view: pointer + length, zero allocations.
Implement Span<T> — a lightweight, non-owning view over a contiguous range (a pointer + a length). It is the idiom behind std::span: pass arrays and vectors to functions without copying and without coupling to a specific container.
<typename T>new/malloc forbidden)(T* data, size_t size) and from a C array T(&)[N]begin()/end() so it works in a range-based forN automatically?Store exactly two members: T* data_ and std::size_t size_. Everything else is computed from them.
The array constructor template <std::size_t N> Span(T (&arr)[N]) deduces N, so you can call Span(data_, N) semantics: data_ = arr; size_ = N;.
Hit Submit (or ⌘/Ctrl + ↵) — test results will show up here.