28 explicit ArraySegment(T* _array,
int _offset,
int _size) {
31 size = _size - _offset;
40 T*
toArray()
const {
return array + offset; }
42 explicit operator T*()
const {
return array + offset; }
56 T& operator[](
int index) {
57 if (index < 0 || index >= size) {
58 throw std::out_of_range(
"index is out of range");
60 return array[offset + index];
63 bool operator==(ArraySegment<T>
const& other) {
64 for (
int i = 0; i < std::min(size, other.size); i++) {
65 if (array[offset + i] != other.array[other.offset + i]) {
72 bool operator!=(ArraySegment<T>
const& other) {
return *
this != other; }
74 ArraySegment<T>& operator=(ArraySegment<T>
const& other) {
76 offset = other.offset;
81 static std::shared_ptr<ArraySegment<T>> createArraySegment(T* array,
int size) {
82 return std::make_shared<ArraySegment<T>>(array, size);
85 static std::shared_ptr<ArraySegment<T>> createArraySegment(T* array,
int offset,
int size) {
86 return std::make_shared<ArraySegment<T>>(array, offset, size);