Lines Matching defs:span
27 class span;
35 struct IsSpanImpl<span<T, Extent>> : std::true_type {};
69 // SFINAE check if Array can be converted to a span<T>.
75 // SFINAE check if Container can be converted to a span<T>.
86 // A span is a value type that represents an array of elements of type T. Since
89 // users are encouraged to use it as a pass-by-value parameter. A span does not
90 // own the underlying memory, so care must be taken to ensure that a span does
93 // span is somewhat analogous to std::string_view, but with arbitrary element
96 // span is implicitly convertible from C++ arrays, as well as most [1]
98 // std::vector<T>). A mutable span<T> can also be implicitly converted to an
99 // immutable span<const T>.
101 // Consider using a span for functions that take a data pointer and size
105 // For read-only data access pass a span<const T>: the caller can supply either
106 // a span<const T> or a span<T>, while the callee will have a read-only view.
107 // For read-write access a mutable span<T> is required.
109 // Without span:
120 // With span:
122 // // std::string HexEncode(base::span<const uint8_t> data);
127 // // ssize_t SafeSNPrintf(base::span<char>, const char* fmt, Args...);
137 // const std::vector<int*> => base::span<int* const>
138 // std::vector<const int*> => base::span<const int*>
139 // const std::vector<const int*> => base::span<const int* const>
148 // Differences from [span.objectrep]:
155 // Differences from [span.sub]:
158 // Differences from [span.obs]:
161 // Differences from [span.elem]:
170 // [span], class template span
172 class span {
186 // [span.cons], span constructors, copy, assignment, and destructor
187 constexpr span() noexcept : data_(nullptr), size_(0) {
191 constexpr span(T* data, size_t size) noexcept : data_(data), size_(size) {
195 // Artificially templatized to break ambiguity for span(ptr, 0).
197 constexpr span(T* begin, T* end) noexcept : span(begin, end - begin) {
205 constexpr span(T (&array)[N]) noexcept : span(std::data(array), N) {}
211 constexpr span(std::array<value_type, N>& array) noexcept
212 : span(std::data(array), N) {}
220 constexpr span(const std::array<value_type, N>& array) noexcept
221 : span(std::data(array), N) {}
227 constexpr span(Container& container) noexcept
228 : span(std::data(container), std::size(container)) {}
233 span(const Container& container) noexcept
234 : span(std::data(container), std::size(container)) {}
236 constexpr span(const span& other) noexcept = default;
239 // span<T> to be seamlessly used as a span<const T>, but not the other way
246 constexpr span(const span<U, OtherExtent>& other)
247 : span(other.data(), other.size()) {}
249 constexpr span& operator=(const span& other) noexcept = default;
250 ~span() noexcept = default;
252 // [span.sub], span subviews
254 constexpr span<T, Count> first() const noexcept {
262 constexpr span<T, Count> last() const noexcept {
270 constexpr span<T,
287 constexpr span<T, dynamic_extent> first(size_t count) const noexcept {
293 constexpr span<T, dynamic_extent> last(size_t count) const noexcept {
299 constexpr span<T, dynamic_extent> subspan(
308 // [span.obs], span observers
313 // [span.elem], span element access
328 // [span.iter], span iterator support
354 // span<T, Extent>::extent can not be declared inline prior to C++17, hence this
357 constexpr size_t span<T, Extent>::extent;
359 // [span.comparison], span comparison operators
362 constexpr bool operator==(span<T, X> lhs, span<U, Y> rhs) noexcept {
367 constexpr bool operator!=(span<T, X> lhs, span<U, Y> rhs) noexcept {
372 constexpr bool operator<(span<T, X> lhs, span<U, Y> rhs) noexcept {
378 constexpr bool operator<=(span<T, X> lhs, span<U, Y> rhs) noexcept {
383 constexpr bool operator>(span<T, X> lhs, span<U, Y> rhs) noexcept {
388 constexpr bool operator>=(span<T, X> lhs, span<U, Y> rhs) noexcept {
392 // [span.objectrep], views of object representation
394 span<const uint8_t, (X == dynamic_extent ? dynamic_extent : sizeof(T) * X)>
395 as_bytes(span<T, X> s) noexcept {
402 span<uint8_t, (X == dynamic_extent ? dynamic_extent : sizeof(T) * X)>
403 as_writable_bytes(span<T, X> s) noexcept {
407 // Type-deducing helpers for constructing a span.
409 constexpr span<T> make_span(T* data, size_t size) noexcept {
414 constexpr span<T> make_span(T* begin, T* end) noexcept {
419 constexpr span<T, N> make_span(T (&array)[N]) noexcept {
424 constexpr span<T, N> make_span(std::array<T, N>& array) noexcept {
429 constexpr span<const T, N> make_span(const std::array<T, N>& array) noexcept {
436 constexpr span<T> make_span(Container& container) noexcept {
444 constexpr span<T> make_span(const Container& container) noexcept {
449 constexpr span<T, X> make_span(const span<T, X>& span) noexcept {
450 return span;