16#ifndef NROS_CPP_SPAN_HPP
17#define NROS_CPP_SPAN_HPP
30template <
typename T>
struct Span {
37 constexpr const T*
data()
const {
return ptr; }
39 constexpr size_t size()
const {
return len; }
41 constexpr bool empty()
const {
return len == 0; }
61 constexpr const char*
data()
const {
return ptr; }
63 constexpr size_t size()
const {
return len; }
65 constexpr bool empty()
const {
return len == 0; }
69 constexpr const char*
begin()
const {
return ptr; }
71 constexpr const char*
end()
const {
return ptr +
len; }
103 unsigned char tmp[
sizeof(
T)];
104#if defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && \
105 __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
106 for (
size_t b = 0;
b <
sizeof(
T); ++
b)
109 for (
size_t b = 0;
b <
sizeof(
T); ++
b)
constexpr size_t size() const
Number of elements.
Definition span.hpp:95
size_t count
Number of elements.
Definition span.hpp:92
constexpr bool empty() const
True if the view contains zero elements.
Definition span.hpp:97
const uint8_t * bytes
Pointer to the first element's little-endian bytes. Borrowed.
Definition span.hpp:90
T operator[](size_t i) const
Definition span.hpp:101
constexpr const T * data() const
Pointer to the underlying storage.
Definition span.hpp:37
constexpr bool empty() const
True if the view contains zero elements.
Definition span.hpp:41
const T * ptr
Pointer to the first element. Borrowed — caller-owned storage.
Definition span.hpp:32
constexpr size_t size() const
Number of elements (alias for len).
Definition span.hpp:39
constexpr const T * end() const
Iterator past the last element.
Definition span.hpp:47
constexpr const T * begin() const
Iterator to the first element.
Definition span.hpp:45
constexpr const T & operator[](size_t i) const
Element access; no bounds check.
Definition span.hpp:43
size_t len
Number of elements in the view.
Definition span.hpp:34
constexpr size_t size() const
Number of bytes.
Definition span.hpp:63
const char * ptr
Pointer to the first byte. Not null-terminated.
Definition span.hpp:56
constexpr char operator[](size_t i) const
Byte access; no bounds check.
Definition span.hpp:67
bool equals(const char *cstr) const
True if cstr (null-terminated) has the same length and bytes.
Definition span.hpp:74
constexpr const char * data() const
Pointer to the underlying bytes.
Definition span.hpp:61
constexpr const char * begin() const
Iterator to the first byte.
Definition span.hpp:69
constexpr bool empty() const
True if the view contains zero bytes.
Definition span.hpp:65
size_t len
Number of bytes in the view.
Definition span.hpp:58
constexpr const char * end() const
Iterator past the last byte.
Definition span.hpp:71