source: cpp/common/nonstd_span.h @ 1203

Last change on this file since 1203 was 1183, checked in by Maciej Komosinski, 2 years ago

Cosmetic

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
10template<class ElementType> class span
11{
12public:
13        constexpr span() noexcept
14        {
15                data_ = NULL;
16                size_ = 0;
17        }
18        constexpr span(ElementType* first, size_t count) noexcept
19        {
20                data_ = first;
21                size_ = count;
22        }
23        constexpr span(ElementType* first, ElementType* end) noexcept
24        {
25                data_ = first;
26                size_ = end - first;
27        }
28        template<size_t N> constexpr span(ElementType(&arr)[N]) noexcept
29        {
30                data_ = arr;
31                size_ = N;
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
41protected:
42        ElementType* data_;
43        size_t size_;
44};
45
46#endif
Note: See TracBrowser for help on using the repository browser.