Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qspan.qdoc
Go to the documentation of this file.
1// Copyright (C) 2023 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4/*!
5 \class QSpan
6 \inmodule QtCore
7 \since 6.7
8 \brief A non-owning container over contiguous data.
9 \ingroup tools
10 \reentrant
11
12 A QSpan references a contiguous portion of another contiguous container.
13 It acts as an interface type for all kinds of contiguous containers,
14 without the need to construct an owning container such as QList or
15 std::vector first.
16
17 The data referenced by a QSpan may be represented as an array (or
18 array-compatible data-structure such as QList, std::vector,
19 QVarLengthArray, etc.). QSpan itself merely stores a pointer to the data,
20 so users must ensure that QSpan objects do not outlive the data they
21 reference.
22
23 Unlike views such as QStringView, QLatin1StringView and QUtf8StringView,
24 referenced data can be modified through a QSpan object. To prevent this,
25 construct a QSpan over a \c{const T} (see \l{Const and Mutable Spans}):
26
27 \code
28 int numbers[] = {0, 1, 2};
29 QSpan<int> span = numbers;
30 span[0] = 42;
31 // numbers == {42, 1, 2};
32 QSpan<const int> cspan = numbers;
33 cspan[0] = 0; // ERROR: cspan[0] is read-only
34 \endcode
35
36 \target variable-fixed-spans
37 \section2 Variable-Size and Fixed-Size Spans
38
39 A QSpan can be \e{fixed-size} or \e{variable-sized}.
40
41 A variable-sized span is formed by omitting the second template argument
42 (or setting it to \c{std::dynamic_extent}, which is, however, only
43 available in C++20 builds), as seen in the example above.
44
45 A fixed-size span is formed by passing a number as the second template
46 argument:
47
48 \code
49 int numbers[] = {0, 1, 2};
50 QSpan<int, 3> span = numbers;
51 QSpan<const int, 3> = numbers; // also OK
52 \endcode
53
54 As the name suggests, a fixed-size span's size() is fixed at compile-time
55 whereas the size() of a variable-sized span is determined only at run-time.
56
57 A fixed-size span is not default-constructible (unless its \l extent is zero
58 (0)). A variable-sized span \e{is} default-constructible and will have
59 \c{data() == nullptr} and \c{size() == 0}.
60
61 A fixed-size span can be implicitly converted into a variable-sized one.
62 The opposite direction (variable-length into fixed-length) has the
63 precondition that both span's sizes must match.
64
65 \target const-mutable-spans
66 \section2 Const and Mutable Spans
67
68 Unlike with owning containers, \c{const} is \e{shallow} in QSpan: you can
69 still modify the data through a const QSpan (but not through a
70 \c{QSpan<const T>}), and begin() and end() are not overloaded on
71 \c{const}/non-\c{const}. There are cbegin() and cend(), though, that return
72 const_iterators which prevent modification of the data even though \c{T} is
73 not const:
74 \code
75 int numbers[] = {0, 1, 2};
76 const QSpan<int> span = numbers;
77 span.front() = 42; // OK, numbers[0] == 42 now
78 *span.begin() = 31; // OK, numbers[0] == 31 now
79 *span.cbegin() = -1; // ERROR: cannot assign through a const_iterator
80 \endcode
81
82 \target other-span-properties
83 \section2 Other Properties
84
85 QSpan should be passed by value, not by reference-to-const:
86
87 \code
88 void consume(QSpan<const int> data); // OK
89 void consume(const QSpan<const int> &data); // works, but is non-idiomatic and less efficient
90 \endcode
91
92 \c{QSpan<T,N>} is a \e{Literal Type}, regardless of whether \c{T} is a
93 Literal Type or not.
94
95 \target span-STL
96 \section2 QSpan vs. std::span
97
98 QSpan is closely modelled after
99 \l{https://en.cppreference.com/w/cpp/container/span}{std::span}, but has a
100 few differences which we'll discuss here. Since they both implicitly
101 convert into each other, you're free to choose whichever one you like best
102 in your own code.
103
104 \list
105 \li QSpan is using the signed qsizetype as \c{size_type}
106 whereas \c{std::span} uses \c{size_t}.
107 \li (since Qt 6.9) \c{QSpan<const T>} doesn't detach Qt containers, \c{std::span} does.
108 \li All QSpan constructors are implicit;
109 many \c{std::span} ones are \c{explicit}.
110 \li QSpan can be constructed from rvalue owning containers, \c{std::span} can not.
111 \endlist
112
113 The last two are required for source-compatibility when functions that took
114 owning containers are converted to take QSpan instead, which is a
115 vitally-important use-case in Qt. The use of qsizetype is for consistency
116 with the rest of Qt containers. QSpan template arguments still use size_t
117 to avoid introducing unnecessary error conditions (negative sizes).
118
119 \target span-compatible-iterators
120 \section2 Compatible Iterators
121
122 QSpan can be constructed from an iterator and size or from an
123 iterator pair, provided the iterators are \e{compatible} ones.
124 Eventually, this should mean C++20 \c{std::contiguous_iterator} and
125 \c{std::sentinel_for}, but while Qt still supports C++17, only raw pointers
126 are considered contiguous iterators.
127
128 \target span-compatible-ranges
129 \section2 Compatible Ranges
130
131 QSpan can also be constructed from a \e{compatible} range. A range is
132 compatible if it has \l{span-compatible-iterators}{compatible iterators}.
133
134 \sa QList, QStringView, QLatin1StringView, QUtf8StringView
135*/
136
137//
138// Nested types and constants
139//
140
141/*!
142 \typedef QSpan::element_type
143
144 An alias for \c{T}. Includes the \c{const}, if any.
145
146 This alias is provided for compatbility with the STL.
147
148 \sa value_type, pointer, {Const and Mutable Spans}
149*/
150
151/*!
152 \typedef QSpan::value_type
153
154 An alias for \c{T}. Excludes the \c{const}, if any.
155
156 This alias is provided for compatbility with the STL.
157
158 \sa element_type, {Const and Mutable Spans}
159*/
160
161/*!
162 \typedef QSpan::size_type
163
164 An alias for qsizetype. This \l{span-STL}{differs from \c{std::span}}.
165
166 This alias is provided for compatbility with the STL.
167*/
168
169/*!
170 \typedef QSpan::difference_type
171
172 An alias for qptrdiff. This \l{span-STL}{differs from \c{std::span}}.
173
174 This alias is provided for compatbility with the STL.
175*/
176
177/*!
178 \typedef QSpan::pointer
179
180 An alias for \c{T*} and \c{element_type*}, respectively. Includes the \c{const}, if any.
181
182 This alias is provided for compatbility with the STL.
183
184 \sa element_type, const_pointer, reference, iterator, {Const and Mutable Spans}
185*/
186
187/*!
188 \typedef QSpan::const_pointer
189
190 An alias for \c{const T*} and \c{const element_type*}, respectively.
191
192 This alias is provided for compatbility with the STL.
193
194 \sa element_type, pointer, const_reference, const_iterator, {Const and Mutable Spans}
195*/
196
197/*!
198 \typedef QSpan::reference
199
200 An alias for \c{T&} and \c{element_type&}, respectively. Includes the \c{const}, if any.
201
202 This alias is provided for compatbility with the STL.
203
204 \sa element_type, const_reference, pointer, {Const and Mutable Spans}
205*/
206
207/*!
208 \typedef QSpan::const_reference
209
210 An alias for \c{const T&} and \c{const element_type&}, respectively.
211
212 This alias is provided for compatbility with the STL.
213
214 \sa element_type, reference, const_pointer, {Const and Mutable Spans}
215*/
216
217/*!
218 \typedef QSpan::iterator
219
220 An alias for \c{T*} and \c{pointer}, respectively. Includes the \c{const}, if any.
221
222 \sa pointer, const_iterator, reverse_iterator, {Const and Mutable Spans}
223*/
224
225/*!
226 \typedef QSpan::const_iterator
227
228 An alias for \c{const T*} and \c{const_pointer}, respectively.
229
230 \sa const_pointer, iterator, const_reverse_iterator, {Const and Mutable Spans}
231*/
232
233/*!
234 \typedef QSpan::reverse_iterator
235
236 An alias for \c{std::reverse_iterator<iterator>}. Includes the \c{const}, if any.
237
238 \sa iterator, const_reverse_iterator, {Const and Mutable Spans}
239*/
240
241/*!
242 \typedef QSpan::const_reverse_iterator
243
244 An alias for \c{std::reverse_iterator<const_iterator>}.
245
246 \sa const_iterator, reverse_iterator, {Const and Mutable Spans}
247*/
248
249/*!
250 \variable QSpan::extent
251
252 The second template argument of \c{QSpan<T, E>}, that is, \c{E}. This is
253 \c{std::dynamic_extent} for \l{variable-fixed-spans}{variable-sized spans}.
254
255 \note While all other sizes and indexes in QSpan use qsizetype, this
256 variable, like \c{E}, is actually of type \c{size_t}, for compatibility with
257 \c{std::span} and \c{std::dynamic_extent}.
258
259 \sa size()
260*/
261
262//
263// Constructors and SMFs
264//
265
266/*!
267 \fn template <typename T, size_t E> QSpan<T,E>::QSpan()
268
269 Default constructor.
270
271 This constructor is only present if \c{E} is either zero (0) or
272 \c{std::dynamic_extent}. In other words: only fixed-zero-sized or variable-sized spans
273 are default-constructible.
274
275 \sa extent, {Variable-Size and Fixed-Size Spans}
276*/
277
278/*!
279 \fn template <typename T, size_t E> QSpan<T,E>::QSpan(const QSpan &other)
280 \fn template <typename T, size_t E> QSpan<T,E>::QSpan(QSpan &&other)
281 \fn template <typename T, size_t E> QSpan<T,E> &QSpan<T,E>::operator=(const QSpan &other)
282 \fn template <typename T, size_t E> QSpan<T,E> &QSpan<T,E>::operator=(QSpan &&other)
283 \fn template <typename T, size_t E> QSpan<T,E>::~QSpan()
284
285 These Special Member Functions are implicitly-defined.
286
287 \note Moves are equivalent to copies. Only data() and size() are copied
288 from span to span, not the referenced data.
289*/
290
291/*!
292 \fn template <typename T, size_t E> template <typename It, QSpan<T, E>::if_compatible_iterator<It>> QSpan<T,E>::QSpan(It first, qsizetype count)
293
294 Constructs a QSpan referencing the data starting at \a first and having length
295 \a count.
296
297 \c{[first, count)} must be a valid range.
298
299 \constraints \c{It} is \l{span-compatible-iterators}{a compatible iterator}.
300*/
301
302/*!
303 \fn template <typename T, size_t E> template <typename It, QSpan<T, E>::if_compatible_iterator<It>> QSpan<T,E>::QSpan(It first, It last)
304
305 Constructs a QSpan referencing the data starting at \a first and having length
306 (\a last - \a first).
307
308 \c{[first, last)} must be a valid range.
309
310 \constraints \c{It} is \l{span-compatible-iterators}{a compatible iterator}.
311*/
312
313/*!
314 \fn template <typename T, size_t E> template <size_t N> QSpan<T,E>::QSpan(q20::type_identity_t<T> (&arr)[N]);
315 \fn template <typename T, size_t E> template <typename S, size_t N, QSpan<T, E>::if_qualification_conversion<S> = true> QSpan<T,E>::QSpan(std::array<S, N> &arr);
316 \fn template <typename T, size_t E> template <typename S, size_t N, QSpan<T, E>::if_qualification_conversion<S> = true> QSpan<T,E>::QSpan(const std::array<S, N> &arr);
317
318 Constructs a QSpan referencing the data in the supplied array \a arr.
319
320 \note \c{q20::type_identity_t} is a C++17 backport of C++20's
321 \l{https://en.cppreference.com/w/cpp/types/type_identity}{\c{std::type_identity_t}}.
322
323 \constraints
324 \list
325 \li either \c{N} or \l{extent} are \c{std::dynamic_extent} or otherwise \l{extent} \c{==} \c{N}
326 \li and either \c{S} or \c{const S} are the same as \c{T}.
327 \endlist
328*/
329
330/*!
331 \fn template <typename T, size_t E> template <typename Range, QSpan<T, E>::if_compatible_range<Range> = true> QSpan<T,E>::QSpan(Range &&r)
332
333 Constructs a QSpan referencing the data in the supplied range \a r.
334
335 \constraints \c{Range} is \l{span-compatible-ranges}{a compatible range}.
336*/
337
338/*!
339 \fn template <typename T, size_t E> template <typename S, size_t N, QSpan<T, E>::if_qualification_conversion<S> = true> QSpan<T,E>::QSpan(QSpan<S, N> other);
340 \fn template <typename T, size_t E> template <typename S, size_t N, QSpan<T, E>::if_qualification_conversion<S> = true> QSpan<T,E>::QSpan(std::span<S, N> other);
341
342 Constructs a QSpan referencing the data in the supplied span \a other.
343
344 \constraints
345 \list
346 \li either \c{N} or \l{extent} are \c{std::dynamic_extent} or \l{extent} \c{==} \c{N}
347 \li and either \c{S} or \c{const S} are the same as \c{T}.
348 \endlist
349*/
350
351/*!
352 \fn template <typename T, size_t E> QSpan<T, E>::QSpan(std::initializer_list<value_type> il);
353
354 Constructs a QSpan referencing the data in the supplied initializer list \a il.
355
356 \note This constructor is \c{noexcept} only if \c{E} is \c{std::dynamic_extent}.
357
358 \note If \c{E} is not \c{std::dynamic_extent} and the size of \a il is not \c{E}, the behavior is undefined.
359
360 \constraints \c{T} is \c{const}-qualified.
361
362 \sa {Const and Mutable Spans}
363*/
364
365//
366// Member functions: sizes
367//
368
369/*!
370 \fn template <typename T, size_t E> auto QSpan<T, E>::size() const
371
372 Returns the size of the span, that is, the number of elements it references.
373
374 \sa size_bytes(), empty(), isEmpty()
375*/
376
377/*!
378 \fn template <typename T, size_t E> auto QSpan<T, E>::size_bytes() const
379
380 Returns the size of the span in bytes, that is, the number of elements
381 multiplied by \c{sizeof(T)}.
382
383 \sa size(), empty(), isEmpty()
384*/
385
386/*!
387 \fn template <typename T, size_t E> auto QSpan<T, E>::empty() const
388 \fn template <typename T, size_t E> auto QSpan<T, E>::isEmpty() const
389
390 Returns whether the span is empty, that is, whether \c{size() == 0}.
391
392 These functions do the same thing: empty() is provided for STL
393 compatibility and isEmpty() is provided for Qt compatibility.
394
395 \sa size(), size_bytes()
396*/
397
398//
399// element access
400//
401
402/*!
403 \fn template <typename T, size_t E> QSpan<T, E>::operator[](size_type idx) const
404
405 Returns a reference to the element at index \a idx in the span.
406
407 The index must be in range, that is, \a idx >= 0 and \a idx < size(),
408 otherwise the behavior is undefined.
409
410 \sa front(), back(), size(), empty(), {Const and Mutable Spans}
411*/
412
413/*!
414 \fn template <typename T, size_t E> auto QSpan<T, E>::front() const
415
416 Returns a reference to the first element in the span.
417
418 The span must not be empty, otherwise the behavior is undefined.
419
420 \sa operator[](), back(), size(), empty(), {Const and Mutable Spans}
421*/
422
423/*!
424 \fn template <typename T, size_t E> auto QSpan<T, E>::back() const
425
426 Returns a reference to the last element in the span.
427
428 The span must not be empty, otherwise the behavior is undefined.
429
430 \sa operator[](), front(), size(), empty(), {Const and Mutable Spans}
431*/
432
433/*!
434 \fn template <typename T, size_t E> auto QSpan<T, E>::data() const
435
436 Returns a pointer to the beginning of the span.
437
438 The same as calling begin().
439
440 \sa begin(), front(), {Const and Mutable Spans}
441*/
442
443//
444// iterators
445//
446
447/*!
448 \fn template <typename T, size_t E> auto QSpan<T, E>::begin() const
449
450 Returns an interator pointing at the beginning of the span.
451
452 Because QSpan iterators are just pointers, this is the same as calling
453 data().
454
455 \sa end(), cbegin(), rbegin(), crbegin(), data(), {Const and Mutable Spans}
456*/
457
458/*!
459 \fn template <typename T, size_t E> auto QSpan<T, E>::end() const
460
461 Returns an iterator pointing to one past the end of the span.
462
463 Because QSpan iterators are just pointers, this it the same as calling
464 \c{data() + size()}.
465
466 \sa begin(), cend(), rend(), crend(), data(), size(), {Const and Mutable Spans}
467*/
468
469/*!
470 \fn template <typename T, size_t E> auto QSpan<T, E>::cbegin() const
471
472 Returns a const_iterator pointing to the beginning of the span.
473
474 This will return a read-only iterator even if \c{T} is not \c{const}:
475 \code
476 QSpan<int> span = ~~~;
477 *span.begin() = 42; // OK
478 *span.cbegin() = 42; // ERROR: cannot assign through a const_iterator
479 \endcode
480
481 \sa cend(), begin(), crbegin(), rbegin(), data(), {Const and Mutable Spans}
482*/
483
484/*!
485 \fn template <typename T, size_t E> auto QSpan<T, E>::cend() const
486
487 Returns a const_iterator pointing to one past the end of the span.
488
489 \sa cbegin(), end(), crend(), rend(), data(), size(), {Const and Mutable Spans}
490*/
491
492/*!
493 \fn template <typename T, size_t E> auto QSpan<T, E>::rbegin() const
494
495 Returns a reverse_iterator pointing to the beginning of the reversed span.
496
497 \sa rend(), crbegin(), begin(), cbegin(), {Const and Mutable Spans}
498*/
499
500/*!
501 \fn template <typename T, size_t E> auto QSpan<T, E>::rend() const
502
503 Returns a reverse_iterator pointing to one past the end of the reversed span.
504
505 \sa rbegin(), crend(), end(), cend(), {Const and Mutable Spans}
506*/
507
508/*!
509 \fn template <typename T, size_t E> auto QSpan<T, E>::crbegin() const
510
511 Returns a const_reverse_iterator pointing to the beginning of the reversed span.
512
513 \sa crend(), rbegin(), cbegin(), begin(), {Const and Mutable Spans}
514*/
515
516/*!
517 \fn template <typename T, size_t E> auto QSpan<T, E>::crend() const
518
519 Returns a const_reverse_iterator pointing to one past the end of the reversed span.
520
521 \sa crbegin(), rend(), cend(), end(), {Const and Mutable Spans}
522*/
523
524//
525// compile-time subspans:
526//
527
528/*!
529 \fn template <typename T, size_t E> template <std::size_t Count> auto QSpan<T, E>::first() const
530 \keyword first-t
531
532 Returns a \l{variable-fixed-spans}{fixed-sized} span of size \c{Count}
533 referencing the first \c{Count} elements of \c{*this}.
534
535 The span must hold at least \c{Count} elements (\c{E} >= \c{Count} \e{and}
536 size() >= \c{Count}), otherwise the behavior is undefined.
537
538 \sa first(QSpan<T,E>::size_type), last(), subspan()
539*/
540
541/*!
542 \fn template <typename T, size_t E> template <std::size_t Count> auto QSpan<T, E>::last() const
543 \keyword last-t
544
545 Returns a \l{variable-fixed-spans}{fixed-sized} span of size \c{Count}
546 referencing the last \c{Count} elements of \c{*this}.
547
548 The span must hold at least \c{Count} elements (\c{E} >= \c{Count} \e{and}
549 size() >= \c{Count}), otherwise the behavior is undefined.
550
551 \sa last(QSpan<T,E>::size_type), first(), subspan()
552*/
553
554/*!
555 \fn template <typename T, size_t E> template <std::size_t Offset> auto QSpan<T, E>::subspan() const
556 \keyword subspan-t1
557
558 Returns a span of size \c{E - Offset} referencing the remainder of this span
559 after dropping the first \c{Offset} elements.
560
561 If \c{*this} is a variable-sized span, the return type is a variable-sized
562 span, otherwise it is a fixed-sized span.
563
564 This span must hold at least \c{Offset} elements (\c{E} >= \c{Offset} \e{and}
565 size() >= \c{Offset}), otherwise the behavior is undefined.
566
567 \sa subspan(QSpan<T,E>::size_type), subspan(), first(), last()
568 \sa {Variable-Size and Fixed-Size Spans}
569*/
570
571/*!
572 \fn template <typename T, size_t E> template <std::size_t Offset, std::size_t Count> auto QSpan<T, E>::subspan() const
573 \keyword subspan-t2
574
575 Returns a span of size \c{Count} referencing the \c{Count} elements of this
576 span starting at \c{Offset}.
577
578 If \c{*this} is a variable-sized span, the return type is a variable-sized
579 span, otherwise it is a fixed-sized span.
580
581 This span must hold at least \c{Offset + Count} elements (\c{E} >=
582 \c{Offset + Count} \e{and} size() >= \c{Offset + Count}), otherwise the
583 behavior is undefined.
584
585 \sa subspan(QSpan<T,E>::size_type, QSpan<T,E>::size_type), subspan(), first(), last()
586 \sa {Variable-Size and Fixed-Size Spans}
587*/
588
589//
590// runtime subspans:
591//
592
593/*!
594 \fn template <typename T, size_t E> auto QSpan<T, E>::first(qsizetype n) const
595 \keyword first-n
596
597 Returns a \l{variable-fixed-spans}{variable-sized} span of size \a n
598 referencing the first \a n elements of \c{*this}.
599
600 \a n must be non-negative.
601
602 The span must hold at least \a n elements (\c{E} >= \a n \e{and} size() >=
603 \a n), otherwise the behavior is undefined.
604
605 \sa {first-t}{first<N>()}, last(QSpan<T,E>::size_type), subspan(QSpan<T,E>::size_type),
606 subspan(QSpan<T,E>::size_type, QSpan<T,E>::size_type)
607 \sa sliced(), chopped()
608*/
609
610/*!
611 \fn template <typename T, size_t E> auto QSpan<T, E>::last(qsizetype n) const
612 \keyword last-n
613
614 Returns a \l{variable-fixed-spans}{variable-sized} span of size \a n
615 referencing the last \a n elements of \c{*this}.
616
617 \a n must be non-negative.
618
619 The span must hold at least \a n elements (\c{E} >= \a n \e{and}
620 size() >= \a n), otherwise the behavior is undefined.
621
622 \sa last(), first(QSpan<T,E>::size_type), subspan(QSpan<T,E>::size_type),
623 subspan(QSpan<T,E>::size_type, QSpan<T,E>::size_type), sliced(), chopped()
624*/
625
626/*!
627 \fn template <typename T, size_t E> auto QSpan<T, E>::subspan(qsizetype pos) const
628 \fn template <typename T, size_t E> auto QSpan<T, E>::sliced(qsizetype pos) const
629 \keyword subspan-n1
630
631 Returns a \l{variable-fixed-spans}{variable-sized} span of size \c{size() -
632 pos} referencing the remainder of this span after dropping the first \a pos
633 elements.
634
635 \a pos must be non-negative.
636
637 This span must hold at least \a pos elements (\c{E} >= \a pos \e{and}
638 size() >= \a pos), otherwise the behavior is undefined.
639
640 These functions do the same thing: subspan() is provided for STL
641 compatibility and sliced() is provided for Qt compatibility.
642
643 \sa subspan(), first(QSpan<T,E>::size_type), last(QSpan<T,E>::size_type), chopped(), slice()
644*/
645
646/*!
647 \fn template <typename T, size_t E> auto QSpan<T, E>::subspan(qsizetype pos, qsizetype n) const
648 \fn template <typename T, size_t E> auto QSpan<T, E>::sliced(qsizetype pos, qsizetype n) const
649 \keyword subspan-n2
650
651 Returns a \l{variable-fixed-spans}{variable-sized} span of size \a n
652 referencing the \a n elements of this span starting at \a pos.
653
654 Both \a pos and \a n must be non-negative.
655
656 This span must hold at least \c{pos + n} elements (\c{E} >=
657 \c{pos + n} \e{and} size() >= \c{pos + n}), otherwise the
658 behavior is undefined.
659
660 These functions do the same thing: subspan() is provided for STL
661 compatibility and sliced() is provided for Qt compatibility.
662
663 \sa subspan(), first(QSpan<T,E>::size_type), last(QSpan<T,E>::size_type), chopped(), slice()
664*/
665
666/*!
667 \fn template <typename T, size_t E> auto QSpan<T,E>::chopped(qsizetype n) const
668 \since 6.9
669
670 Returns a \l{variable-fixed-spans}{variable-sized} span of size size() - \a
671 n referencing the first size() - \a n elements of this span.
672
673 Same as \c{first(size() - n)}.
674
675 \a n must be non-negative.
676
677 This span must hold at least \a n elements (\c{E} >= \a n \e{and} size() >=
678 \a n), otherwise the behavior is undefined.
679
680 \sa subspan(), first(QSpan<T,E>::size_type), last(QSpan<T,E>::size_type), chop()
681*/
682
683/*!
684 \fn template <typename T, size_t E> void QSpan<T,E>::chop(qsizetype n)
685 \since 6.9
686
687 Same as \c{*this = chopped(}\a{n}\c{)}.
688
689 This function is only available on \l{variable-fixed-spans}{variable-sized spans}.
690
691 \sa chopped()
692*/
693
694/*!
695 \fn template <typename T, size_t E> void QSpan<T,E>::slice(qsizetype pos)
696 \since 6.9
697
698 Same as \c{*this = sliced(}\a{pos}\c{)}.
699
700 This function is only available on \l{variable-fixed-spans}{variable-sized spans}.
701
702 \sa sliced()
703*/
704
705/*!
706 \fn template <typename T, size_t E> void QSpan<T,E>::slice(qsizetype pos, qsizetype n)
707 \since 6.9
708
709 Same as \c{*this = sliced(}\a{pos}\c{, }\a{n}\c{)}.
710
711 This function is only available on \l{variable-fixed-spans}{variable-sized spans}.
712
713 \sa sliced()
714*/
715
716/*!
717 \fn template <typename T, size_t E> auto QSpan<T, E>::as_bytes(QSpan s)
718 \since 6.8
719
720 Returns \a s as a \c{QSpan<const std::byte, E'>} whose size() is equal to
721 \c{s.size_bytes()}.
722
723 If \c{E} is \c{std::dynamic_extent} then so is \c{E'}.
724 Otherwise, \c{E' = E * sizeof(T)}.
725
726 \note \c{q20::dynamic_extent} is a C++17 backport of C++20's
727 \l{https://en.cppreference.com/w/cpp/container/span/dynamic_extent}{\c{std::dynamic_extent}}.
728
729 \sa as_writable_bytes(), size_bytes(), {Const and Mutable Spans}
730*/
731
732/*!
733 \fn template <typename T, size_t E> auto QSpan<T, E>::as_writable_bytes(QSpan s)
734 \since 6.8
735
736 Returns \a s as a \c{QSpan<std::byte, E'>} whose size() is equal to
737 \c{s.size_bytes()}.
738
739 If \c{E} is \c{std::dynamic_extent} then so is \c{E'}.
740 Otherwise, \c{E' = E * sizeof(T)}.
741
742 \note \c{q20::dynamic_extent} is a C++17 backport of C++20's
743 \l{https://en.cppreference.com/w/cpp/container/span/dynamic_extent}{\c{std::dynamic_extent}}.
744
745 \constraints \c{!std::is_const_v<T>}.
746
747 \sa as_bytes(), size_bytes(), {Const and Mutable Spans}
748*/