source: cpp/common/nonstd_span.h @ 1282

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

Cosmetic

File size: 1.0 KB
RevLine 
[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
10template<class ElementType> class span
11{
12public:
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
41protected:
42        ElementType* data_;
43        size_t size_;
44};
45
46#endif
Note: See TracBrowser for help on using the repository browser.