12 #include <type_traits>
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)
22 #if defined(__clang__)
23 #if __has_attribute(lifetimebound)
24 #define SPAN_ATTR_LIFETIMEBOUND [[clang::lifetimebound]]
26 #define SPAN_ATTR_LIFETIMEBOUND
29 #define SPAN_ATTR_LIFETIMEBOUND
93 template <
typename C>
class Span {
97 template <
class T>
struct is_Span_int :
public std::false_type {};
111 template <
typename T,
112 typename std::enable_if<
113 std::is_convertible<T (*)[], C (*)[]>::value,
int>::type = 0>
123 template <
typename T,
124 typename std::enable_if<
125 std::is_convertible<T (*)[], C (*)[]>::value,
int>::type = 0>
142 template <
typename O,
143 typename std::enable_if<
144 std::is_convertible<O (*)[], C (*)[]>::value,
int>::type = 0>
170 template <
typename V>
173 typename std::enable_if<
176 typename std::remove_pointer<
177 decltype(std::declval<V &>().
data())>::type (*)[],
179 std::is_convertible<decltype(std::declval<V &>().
size()),
181 std::nullptr_t>::type =
nullptr)
184 template <
typename V>
187 typename std::enable_if<
190 typename std::remove_pointer<
191 decltype(std::declval<const V &>().
data())>::type (*)[],
193 std::is_convertible<decltype(std::declval<const V &>().
size()),
195 std::nullptr_t>::type =
nullptr)
209 constexpr std::size_t
size() const noexcept {
return m_size; }
210 constexpr
bool empty() const noexcept {
return size() == 0; }
220 std::size_t
count)
const noexcept {
234 return a.size() == b.size() &&
235 std::equal(a.begin(), a.end(), b.begin());
241 return std::lexicographical_compare(a.begin(), a.end(), b.begin(),
254 template <
typename O>
friend class Span;
259 template <
typename T,
typename EndOrSize>
Span(T *, EndOrSize) ->
Span<T>;
264 template <
typename T>
266 !std::is_lvalue_reference_v<T>,
267 const std::remove_pointer_t<decltype(std::declval<T &&>().
data())>>>;
269 template <
typename T>
296 template <
typename T>
298 ->
Span<
typename std::remove_pointer<decltype(
UCharCast(s.data()))>::type> {
306 template <
typename V>
A Span is an object that can refer to a contiguous sequence of objects.
constexpr std::size_t size() const noexcept
constexpr friend bool operator>=(const Span &a, const Span &b) noexcept
Span & operator=(const Span &other) noexcept=default
Default assignment operator.
constexpr friend bool operator>(const Span &a, const Span &b) noexcept
CONSTEXPR_IF_NOT_DEBUG Span< C > subspan(std::size_t offset, std::size_t count) const noexcept
CONSTEXPR_IF_NOT_DEBUG C & back() const noexcept
constexpr Span(C(&a)[N]) noexcept
Construct a Span from an array.
constexpr Span() noexcept
CONSTEXPR_IF_NOT_DEBUG C & front() const noexcept
constexpr C * data() const noexcept
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 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 C * end() const noexcept
constexpr C * begin() const noexcept
constexpr Span(const Span &) noexcept=default
Default copy constructor.
CONSTEXPR_IF_NOT_DEBUG Span< C > last(std::size_t count) const noexcept
CONSTEXPR_IF_NOT_DEBUG Span< C > first(std::size_t count) const noexcept
CONSTEXPR_IF_NOT_DEBUG C & operator[](std::size_t pos) const noexcept
CONSTEXPR_IF_NOT_DEBUG Span< C > subspan(std::size_t offset) const noexcept
constexpr bool empty() const noexcept
constexpr friend bool operator!=(const Span &a, const Span &b) noexcept
constexpr friend bool operator==(const Span &a, const Span &b) noexcept
constexpr Span(const Span< O > &other) noexcept
Implicit conversion of spans between compatible types.
constexpr friend bool operator<(const Span &a, const Span &b) noexcept
constexpr friend bool operator<=(const Span &a, const Span &b) 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,...
#define ASSERT_IF_DEBUG(x)
#define SPAN_ATTR_LIFETIMEBOUND
constexpr auto MakeUCharSpan(V &&v) -> decltype(UCharSpanCast(Span{std::forward< V >(v)}))
Like the Span constructor, but for (const) uint8_t member types only.
Span(T *, EndOrSize) -> Span< T >
constexpr auto UCharSpanCast(Span< T > s) -> Span< typename std::remove_pointer< decltype(UCharCast(s.data()))>::type >
#define CONSTEXPR_IF_NOT_DEBUG
T & SpanPopBack(Span< T > &span)
Pop the last element off a span, and return a reference to that element.
uint8_t * UCharCast(char *c)