Rev | Line | |
---|
[1179] | 1 | // This file is a part of Framsticks SDK. http://www.framsticks.com/
|
---|
| 2 | // Copyright (C) 2019-2022 Maciej Komosinski and Szymon Ulatowski.
|
---|
| 3 | // See LICENSE.txt for details.
|
---|
| 4 |
|
---|
| 5 | #ifndef _NONSTD_SPAN_H_
|
---|
| 6 | #define _NONSTD_SPAN_H_
|
---|
| 7 |
|
---|
| 8 | // Remove this and use std::span when available (c++20)
|
---|
| 9 |
|
---|
| 10 | template<class ElementType> class span
|
---|
| 11 | {
|
---|
| 12 | public:
|
---|
| 13 | constexpr span() noexcept
|
---|
| 14 | {
|
---|
[1183] | 15 | data_ = NULL;
|
---|
| 16 | size_ = 0;
|
---|
[1179] | 17 | }
|
---|
| 18 | constexpr span(ElementType* first, size_t count) noexcept
|
---|
| 19 | {
|
---|
[1183] | 20 | data_ = first;
|
---|
| 21 | size_ = count;
|
---|
[1179] | 22 | }
|
---|
| 23 | constexpr span(ElementType* first, ElementType* end) noexcept
|
---|
| 24 | {
|
---|
[1183] | 25 | data_ = first;
|
---|
| 26 | size_ = end - first;
|
---|
[1179] | 27 | }
|
---|
| 28 | template<size_t N> constexpr span(ElementType(&arr)[N]) noexcept
|
---|
| 29 | {
|
---|
[1183] | 30 | data_ = arr;
|
---|
| 31 | size_ = N;
|
---|
[1179] | 32 | }
|
---|
| 33 |
|
---|
| 34 | size_t size() const { return size_; }
|
---|
| 35 | size_t size_bytes() const { return size_ * sizeof(ElementType); }
|
---|
| 36 | ElementType& operator[](size_t idx) const { return data_[idx]; }
|
---|
| 37 |
|
---|
| 38 | ElementType* begin() const { return data_; }
|
---|
| 39 | ElementType* end() const { return data_ + size_; }
|
---|
| 40 |
|
---|
| 41 | protected:
|
---|
| 42 | ElementType* data_;
|
---|
| 43 | size_t size_;
|
---|
| 44 | };
|
---|
| 45 |
|
---|
| 46 | #endif
|
---|
Note: See
TracBrowser
for help on using the repository browser.