#pragma once #include #include #include template struct Span { public: using element_type = T; using pointer = T*; using reference = T&; using iterator = T*; constexpr Span() noexcept : m_ptr(nullptr), m_count(0) {} constexpr Span(std::nullptr_t) noexcept : Span() {} constexpr Span(T* ptr, size_t count) noexcept : m_ptr(ptr), m_count(count) {} constexpr Span(T* ptr_begin, T* ptr_end) noexcept : m_ptr(ptr_begin), m_count(ptr_end - ptr_begin) {} template constexpr Span(T (&arr)[N]) noexcept : Span(arr, N) { } Span(std::vector& v) noexcept : Span(v.data(), v.size()) {} Span(const std::vector>& v) noexcept : Span(v.data(), v.size()) {} constexpr iterator begin() const { return m_ptr; } constexpr iterator end() const { return m_ptr + m_count; } constexpr reference operator[](size_t i) const { return m_ptr[i]; } constexpr size_t size() const { return m_count; } private: pointer m_ptr; size_t m_count; }; template Span make_span(std::vector& v) { return {v.data(), v.size()}; } template Span make_span(const std::vector& v) { return {v.data(), v.size()}; }