Last change
on this file since 1182 was
1179,
checked in by Maciej Komosinski, 2 years ago
|
"eof" quoting and unquoting functions (used in client-server communication)
|
File size:
1.0 KB
|
Line | |
---|
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 | {
|
---|
15 | data_ = NULL; size_ = 0;
|
---|
16 | }
|
---|
17 | constexpr span(ElementType* first, size_t count) noexcept
|
---|
18 | {
|
---|
19 | data_ = first; size_ = count;
|
---|
20 | }
|
---|
21 | constexpr span(ElementType* first, ElementType* end) noexcept
|
---|
22 | {
|
---|
23 | data_ = first; size_ = end - first;
|
---|
24 | }
|
---|
25 | template<size_t N> constexpr span(ElementType(&arr)[N]) noexcept
|
---|
26 | {
|
---|
27 | data_ = arr; size_ = N;
|
---|
28 | }
|
---|
29 |
|
---|
30 | size_t size() const { return size_; }
|
---|
31 | size_t size_bytes() const { return size_ * sizeof(ElementType); }
|
---|
32 | ElementType& operator[](size_t idx) const { return data_[idx]; }
|
---|
33 |
|
---|
34 | ElementType* begin() const { return data_; }
|
---|
35 | ElementType* end() const { return data_ + size_; }
|
---|
36 |
|
---|
37 | protected:
|
---|
38 | ElementType* data_;
|
---|
39 | size_t size_;
|
---|
40 | };
|
---|
41 |
|
---|
42 | #endif
|
---|
Note: See
TracBrowser
for help on using the repository browser.