#pragma once #include template class ArrayView { public: ArrayView() = default; ArrayView(const ArrayView&) = default; ArrayView(ArrayView&&) = default; ~ArrayView() = default; template ArrayView(Index size, U* data, Index stride=sizeof(T), Index byte_offset=0) : m_data(reinterpret_cast(data) + byte_offset) , m_size(size) , m_stride(stride) { assert(m_data != nullptr || m_size == 0); } explicit ArrayView(std::vector& vector) : m_data(vector.data()) , m_data(vector.size()) {} ArrayView& operator=(const ArrayView&) = default; ArrayView& operator=(ArrayView&&) = default; explicit operator bool() const { return m_size != 0; } Index size() const { return m_size; } Index stride() const { return m_stride; } const T* data() const { return m_data; } T* data() { return m_data; } const T& operator[](Index index) const { assert(index < m_size); return *reinterpret_cast(m_data + index * m_stride); } T& operator[](Index index) { return const_cast(const_cast(*this)[index]); } ArrayView slice(Index start, Index count, Index step=1) { assert(step > 0); assert(start + count * step <= m_size); return ArrayView( count, m_data + start * m_stride, m_stride * step ); } private: Byte* m_data = nullptr; Index m_size = 0; Index m_stride = sizeof(T); }; using Vector3AV = ArrayView; using TriangleAV = ArrayView;