15#define CONSTEXPR_IF_NOT_DEBUG
16#define ASSERT_IF_DEBUG(x) assert((x))
18#define CONSTEXPR_IF_NOT_DEBUG constexpr
19#define ASSERT_IF_DEBUG(x)
23#if __has_attribute(lifetimebound)
24#define SPAN_ATTR_LIFETIMEBOUND [[clang::lifetimebound]]
26#define SPAN_ATTR_LIFETIMEBOUND
29#define SPAN_ATTR_LIFETIMEBOUND
118 template <
typename T,
typename std::enable_if<std::is_convertible<T (*)[], C (*)[]>::value,
int>::type = 0>
126 template <
typename T,
typename std::enable_if<std::is_convertible<T (*)[], C (*)[]>::value,
int>::type = 0>
140 template <
typename O,
typename std::enable_if<std::is_convertible<O (*)[], C (*)[]>::value,
int>::type = 0>
160 template <
typename V>
163 std::is_convertible<
typename std::remove_pointer<
decltype(std::declval<V&>().
data())>::type (*)[], C (*)[]>::value &&
164 std::is_convertible<
decltype(std::declval<V&>().
size()), std::size_t>::value, std::nullptr_t>::type =
nullptr)
167 template <
typename V>
170 std::is_convertible<
typename std::remove_pointer<
decltype(std::declval<const V&>().
data())>::type (*)[], C (*)[]>::value &&
171 std::is_convertible<
decltype(std::declval<const V&>().
size()), std::size_t>::value, std::nullptr_t>::type =
nullptr)
187 constexpr std::size_t
size() const noexcept {
return m_size; }
189 constexpr bool empty() const noexcept {
return size() == 0; }
216 template <
typename O>
friend class Span;
238template <
typename T,
typename EndOrSize>
Span(
T*, EndOrSize) ->
Span<T>;
261 return {
reinterpret_cast<const std::byte*
>(
s.data()),
s.size_bytes()};
266 return {
reinterpret_cast<std::byte*
>(
s.data()),
s.size_bytes()};
281inline unsigned char*
UCharCast(
char* c) {
return reinterpret_cast<unsigned char*
>(c); }
282inline unsigned char*
UCharCast(
unsigned char* c) {
return c; }
283inline unsigned char*
UCharCast(
signed char* c) {
return reinterpret_cast<unsigned char*
>(c); }
284inline unsigned char*
UCharCast(std::byte* c) {
return reinterpret_cast<unsigned char*
>(c); }
285inline const unsigned char*
UCharCast(
const char* c) {
return reinterpret_cast<const unsigned char*
>(c); }
286inline const unsigned char*
UCharCast(
const unsigned char* c) {
return c; }
287inline const unsigned char*
UCharCast(
const signed char* c) {
return reinterpret_cast<const unsigned char*
>(c); }
288inline const unsigned char*
UCharCast(
const std::byte* c) {
return reinterpret_cast<const unsigned char*
>(c); }
A Span is an object that can refer to a contiguous sequence of objects.
CONSTEXPR_IF_NOT_DEBUG Span< C > last(std::size_t count) const noexcept
CONSTEXPR_IF_NOT_DEBUG C & back() const noexcept
constexpr std::size_t size() const noexcept
CONSTEXPR_IF_NOT_DEBUG Span< C > subspan(std::size_t offset) const noexcept
constexpr Span(V &other SPAN_ATTR_LIFETIMEBOUND, typename std::enable_if<!is_Span< V >::value &&std::is_convertible< typename std::remove_pointer< decltype(std::declval< V & >().data())>::type(*)[], C(*)[]>::value &&std::is_convertible< decltype(std::declval< V & >().size()), std::size_t >::value, std::nullptr_t >::type=nullptr)
Construct a Span for objects with .data() and .size() (std::string, std::array, std::vector,...
constexpr Span(C(&a)[N]) noexcept
Construct a Span from an array.
constexpr Span() noexcept
CONSTEXPR_IF_NOT_DEBUG C & operator[](std::size_t pos) const noexcept
CONSTEXPR_IF_NOT_DEBUG Span< C > first(std::size_t count) const noexcept
constexpr C * data() const noexcept
constexpr Span(T *begin, std::size_t size) noexcept
Construct a span from a begin pointer and a size.
CONSTEXPR_IF_NOT_DEBUG Span(T *begin, T *end) noexcept
Construct a span from a begin and end pointer.
constexpr Span(const Span &) noexcept=default
Default copy constructor.
constexpr Span(const V &other SPAN_ATTR_LIFETIMEBOUND, typename std::enable_if<!is_Span< V >::value &&std::is_convertible< typename std::remove_pointer< decltype(std::declval< const V & >().data())>::type(*)[], C(*)[]>::value &&std::is_convertible< decltype(std::declval< const V & >().size()), std::size_t >::value, std::nullptr_t >::type=nullptr)
constexpr std::size_t size_bytes() const noexcept
Span & operator=(const Span &other) noexcept=default
Default assignment operator.
constexpr C * begin() const noexcept
constexpr bool empty() const noexcept
constexpr C * end() const noexcept
CONSTEXPR_IF_NOT_DEBUG C & front() const noexcept
CONSTEXPR_IF_NOT_DEBUG Span< C > subspan(std::size_t offset, std::size_t count) const noexcept
constexpr Span(const Span< O > &other) noexcept
Implicit conversion of spans between compatible types.
Span< std::byte > AsWritableBytes(Span< T > s) noexcept
#define ASSERT_IF_DEBUG(x)
Span< const std::byte > MakeByteSpan(V &&v) noexcept
#define SPAN_ATTR_LIFETIMEBOUND
constexpr auto MakeUCharSpan(V &&v) -> decltype(UCharSpanCast(Span{std::forward< V >(v)}))
Like the Span constructor, but for (const) unsigned char member types only.
T & SpanPopBack(Span< T > &span)
Pop the last element off a span, and return a reference to that element.
std::remove_pointer_t< decltype(std::declval< T & >().data())> DataResult
Span(T *, EndOrSize) -> Span< T >
Span< const std::byte > AsBytes(Span< T > s) noexcept
constexpr auto UCharSpanCast(Span< T > s) -> Span< typename std::remove_pointer< decltype(UCharCast(s.data()))>::type >
unsigned char * UCharCast(char *c)
#define CONSTEXPR_IF_NOT_DEBUG
Span< std::byte > MakeWritableByteSpan(V &&v) noexcept