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