14 #define CONSTEXPR_IF_NOT_DEBUG
15 #define ASSERT_IF_DEBUG(x) assert((x))
17 #define CONSTEXPR_IF_NOT_DEBUG constexpr
18 #define ASSERT_IF_DEBUG(x)
88 constexpr
Span() noexcept : m_data(
nullptr), m_size(0) {}
95 template <typename T, typename std::enable_if<std::is_convertible<T (*)[], C (*)[]>::value,
int>::type = 0>
103 template <typename T, typename std::enable_if<std::is_convertible<T (*)[], C (*)[]>::value,
int>::type = 0>
117 template <typename O, typename std::enable_if<std::is_convertible<O (*)[], C (*)[]>::value,
int>::type = 0>
121 constexpr
Span(
const Span&) noexcept = default;
124 Span& operator=(const
Span& other) noexcept = default;
128 constexpr
Span(C (&a)[N]) noexcept : m_data(a), m_size(N) {}
137 template <typename V, typename std::enable_if<(std::is_const<C>::value || std::is_lvalue_reference<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,
int>::type = 0>
142 constexpr C*
end() const noexcept {
return m_data +
m_size; }
151 return m_data[m_size - 1];
153 constexpr std::size_t
size() const noexcept {
return m_size; }
154 constexpr
bool empty() const noexcept {
return size() == 0; }
163 return Span<C>(m_data + offset, m_size - offset);
181 friend constexpr
bool operator==(
const Span& a,
const Span& b) noexcept {
return a.size() == b.size() && std::equal(a.begin(), a.end(), b.begin()); }
183 friend constexpr
bool operator<(
const Span& a,
const Span& b) noexcept {
return std::lexicographical_compare(a.begin(), a.end(), b.begin(), b.end()); }
188 template <
typename O>
friend class Span;
195 template <
typename V> constexpr
auto MakeSpan(V&& v) ->
typename std::enable_if<!std::is_lvalue_reference<V>::value,
Span<
const typename std::remove_pointer<decltype(v.data())>::type>>::type {
return std::forward<V>(v); }
197 template <
typename V> constexpr
auto MakeSpan(V& v) ->
Span<
typename std::remove_pointer<decltype(v.data())>::type> {
return v; }
200 template <
typename T>
205 T&
back = span[size - 1];
211 inline unsigned char*
UCharCast(
char* c) {
return (
unsigned char*)c; }
212 inline unsigned char*
UCharCast(
unsigned char* c) {
return c; }
213 inline const unsigned char*
UCharCast(
const char* c) {
return (
unsigned char*)c; }
214 inline const unsigned char*
UCharCast(
const unsigned char* c) {
return c; }
CONSTEXPR_IF_NOT_DEBUG Span< C > first(std::size_t count) const noexcept
CONSTEXPR_IF_NOT_DEBUG Span< C > subspan(std::size_t offset) const noexcept
friend constexpr bool operator<(const Span &a, const Span &b) noexcept
constexpr C * end() const noexcept
friend constexpr bool operator<=(const Span &a, const Span &b) noexcept
constexpr Span(T *begin, std::size_t size) noexcept
Construct a span from a begin pointer and a size.
constexpr std::size_t size() const noexcept
constexpr Span(const Span< O > &other) noexcept
Implicit conversion of spans between compatible types.
friend constexpr bool operator>=(const Span &a, const Span &b) noexcept
friend constexpr bool operator!=(const Span &a, const Span &b) noexcept
friend constexpr bool operator==(const Span &a, const Span &b) noexcept
#define ASSERT_IF_DEBUG(x)
friend constexpr bool operator>(const Span &a, const Span &b) noexcept
CONSTEXPR_IF_NOT_DEBUG C & operator[](std::size_t pos) const noexcept
constexpr auto MakeUCharSpan(V &&v) -> decltype(UCharSpanCast(MakeSpan(std::forward< V >(v))))
Like MakeSpan, but for (const) unsigned char member types only.
constexpr Span() noexcept
CONSTEXPR_IF_NOT_DEBUG C & front() const noexcept
CONSTEXPR_IF_NOT_DEBUG Span(T *begin, T *end) noexcept
Construct a span from a begin and end pointer.
constexpr C * begin() const noexcept
constexpr auto UCharSpanCast(Span< T > s) -> Span< typename std::remove_pointer< decltype(UCharCast(s.data()))>::type >
constexpr C * data() const noexcept
#define CONSTEXPR_IF_NOT_DEBUG
CONSTEXPR_IF_NOT_DEBUG C & back() const noexcept
T & SpanPopBack(Span< T > &span)
Pop the last element off a span, and return a reference to that element.
constexpr bool empty() const noexcept
unsigned char * UCharCast(char *c)
A Span is an object that can refer to a contiguous sequence of objects.
constexpr Span(V &&v) noexcept
Construct a Span for objects with .data() and .size() (std::string, std::array, std::vector, ...).
CONSTEXPR_IF_NOT_DEBUG Span< C > last(std::size_t count) const noexcept
CONSTEXPR_IF_NOT_DEBUG Span< C > subspan(std::size_t offset, std::size_t count) const noexcept
Span< A > constexpr MakeSpan(A(&a)[N])
MakeSpan for arrays: