Span
Identify an unowned contiguous memory range
Context
#include <xo/tokenizer/span.hpp>
Identify a sequence of characters stored in contiguous memory.
Lightweight, consists of a pair of pointers.
Does not own storage. Lifetime management for target memory is up to the caller.
Class
-
template<typename CharT>
class span A contiguous range of characters, without ownership.
- Template Parameters:
CharT – type for elements referred to by this span.
Member Variables
- group Span-instance-vars
Type Traits
- group span type traits
Constructors
- group span constructors
Functions
-
inline span()
null span
-
inline span(CharT *lo, CharT *hi)
Create span for the contiguous memory range [
lo,hi)
-
template<typename CharU>
inline span(const span<CharU> &other, std::enable_if_t<std::is_convertible_v<CharU*, CharT*> && !std::is_same_v<CharU, CharT>>* = nullptr) explicit conversion from span
-
inline span()
Access Methods
- group Span-access-methods
General Methods
- group Span-general-methods
Functions
-
inline void discard_until_newline()
strip prefix until first occurence of ‘
’, including the newline
-
template<typename OtherT>
inline span<OtherT> cast() const Create new span over supplied type, with identical (possibly misaligned) endpoints.
Warning
New span uses exactly the same memory addresses. Endpoint pointers may not be aligned.
Implementation assumes code compiled with
enabled.-fno-strict-aliasing
- Template Parameters:
OtherT – element type for new span
-
inline span prefix_upto(CharT *p) const
create span representing prefix up to (but not including)
*p
-
inline span suffix_from(CharT *p) const
Create span starting with position
p. Does boundary checking; will return empty span ifpis outside[lo_,hi)
-
inline bool is_null() const
true iff this span is null. distinct from empty.
-
inline bool empty() const
true iff this span is empty (comprises 0 elements).
-
inline span &operator+=(const span &x)
increase extent of this spans to include
x. Requireshi()==x.lo()
-
inline void print(std::ostream &os) const
print representation for this span on stream
os
-
inline void discard_until_newline()
Operators
- group Span-operators
Functions
-
template<typename CharT>
inline bool operator==(const span<CharT> &lhs, const span<CharT> &rhs) compare spans for equality. Two spans are equal iff both endpoints match exactly.
-
template<typename CharT>