25
Ranges library
[ranges]
25.7
Range adaptors
[range.adaptors]
25.7.29
Chunk view
[range.chunk]
25.7.29.1
Overview
[range.chunk.overview]
1
#
chunk_
view
takes a view and a number
N
and produces a range of views that are
N
-sized non-overlapping successive chunks of the elements of the original view, in order
.
The last view in the range can have fewer than
N
elements
.
2
#
The name
views
::
chunk
denotes a range adaptor object (
[range.
adaptor.
object]
)
.
Given subexpressions
E
and
N
, the expression
views
::
chunk
(
E, N
)
is expression-equivalent to
chunk_
view
(
E, N
)
.
[
Example
1
:
vector v
=
{
1
,
2
,
3
,
4
,
5
}
;
for
(
auto
r
:
v
|
views
::
chunk
(
2
)
)
{
cout
<
<
'['
;
auto
sep
=
""
;
for
(
auto
i
:
r
)
{
cout
<
<
sep
<
<
i; sep
=
", "
;
}
cout
<
<
"] "
;
}
// The above prints
[1, 2] [3, 4] [5]
—
end example
]