2023-11-02 23:30:44 -07:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
namespace glcr {
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
class ArrayView {
|
|
|
|
public:
|
|
|
|
ArrayView() : data_(nullptr), size_(0) {}
|
2023-11-15 18:43:35 -08:00
|
|
|
|
2023-11-02 23:30:44 -07:00
|
|
|
ArrayView(const ArrayView&) = default;
|
2023-11-15 18:43:35 -08:00
|
|
|
ArrayView(ArrayView&&) = default;
|
|
|
|
|
2023-11-02 23:30:44 -07:00
|
|
|
ArrayView(T* data, uint64_t size) : data_(data), size_(size) {}
|
|
|
|
|
2023-11-15 18:43:35 -08:00
|
|
|
// Accessors.
|
|
|
|
T& operator[](uint64_t index) { return data_[index]; }
|
|
|
|
const T& operator[](uint64_t index) const { return data_[index]; }
|
|
|
|
|
2023-11-02 23:30:44 -07:00
|
|
|
T* RawPtr() { return data_; }
|
|
|
|
const T* RawPtr() const { return data_; }
|
|
|
|
|
|
|
|
uint64_t size() const { return size_; }
|
2023-11-15 18:43:35 -08:00
|
|
|
bool empty() const { return size_; }
|
2023-11-02 23:30:44 -07:00
|
|
|
|
|
|
|
private:
|
|
|
|
T* data_;
|
|
|
|
uint64_t size_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace glcr
|