39 using element_type = _Ty;
40 using value_type = _Ty;
41 using index_type = size_t;
42 using difference_type = ptrdiff_t;
44 using const_pointer =
const _Ty*;
45 using reference = _Ty&;
46 using const_reference =
const _Ty&;
48 using iterator = pointer;
49 using const_iterator = const_pointer;
52 span() : data_(
nullptr), size_(0) {}
55 span(_Ty* _begin, _Ty* _end)
56 : data_(_begin), size_(
static_cast<size_t>(_end - _begin)) {
57 assert(_begin <= _end &&
"Invalid range.");
62 span(_Ty* _begin,
size_t _size) : data_(_begin), size_(_size) {}
65 void operator=(
const span& _other) {
71 explicit span(_Ty& _element) : data_(&_element), size_(1) {}
75 template <
size_t _size>
76 span(_Ty (&_array)[_size]) : data_(_array), size_(_size) {}
79 template <
size_t _size>
80 void operator=(_Ty (&_array)[_size]) {
91 assert(_count <= size_ &&
"Count out of range");
92 return {data(), _count};
96 assert(_count <= size_ &&
"Count out of range");
97 return {data() + size_ - _count, _count};
101 assert(_offset <= size_ &&
"Offset out of range");
102 assert(_count <= size_ &&
"Count out of range");
103 assert(_offset <= size_ - _count &&
"Offset + count out of range");
104 return {data_ + _offset, _count};
108 _Ty& operator[](
size_t _i)
const {
109 assert(_i < size_ &&
"Index out of range.");
113 bool empty()
const {
return size_ == 0; }
116 _Ty* data()
const {
return data_; }
120 size_t size()
const {
return size_; }
123 size_t size_bytes()
const {
return size_ *
sizeof(element_type); }
126 iterator begin()
const {
return data_; }
127 iterator end()
const {
return data_ + size_; }