Difference between revisions of "cpp/ranges/chunk view/outer iterator"
From cppreference.com
< cpp | ranges | chunk view
m (→Example: +) |
Andreas Krug (Talk | contribs) m (headers sorted) |
||
(8 intermediate revisions by 2 users not shown) | |||
Line 2: | Line 2: | ||
{{cpp/ranges/chunk_view/navbar}} | {{cpp/ranges/chunk_view/navbar}} | ||
− | {{ddcl|since=c++23| | + | {{ddcl|since=c++23| |
class /*outer-iterator*/ | class /*outer-iterator*/ | ||
}} | }} | ||
− | The return type of {{rlpt|begin|chunk_view::begin}} | + | The return type of {{rlpt|begin|chunk_view::begin}} if {{tt|V}} models {{lconcept|input_range}}. |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
===Member types=== | ===Member types=== | ||
Line 20: | Line 13: | ||
{{dsc|{{tt|iterator_concept}}|{{c|std::input_iterator_tag}}}} | {{dsc|{{tt|iterator_concept}}|{{c|std::input_iterator_tag}}}} | ||
{{dsc|{{tt|difference_type}}|{{c|ranges::range_difference_t<V>}}}} | {{dsc|{{tt|difference_type}}|{{c|ranges::range_difference_t<V>}}}} | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
{{dsc end}} | {{dsc end}} | ||
Line 25: | Line 24: | ||
{{dsc begin}} | {{dsc begin}} | ||
{{dsc mem ctor|cpp/ranges/chunk_view/outer_iterator/outer_iterator|constructs an iterator|notes={{mark c++23}}}} | {{dsc mem ctor|cpp/ranges/chunk_view/outer_iterator/outer_iterator|constructs an iterator|notes={{mark c++23}}}} | ||
+ | |||
{{dsc mem fun|cpp/ranges/chunk_view/outer_iterator/operator*|accesses the element|notes={{mark c++23}}}} | {{dsc mem fun|cpp/ranges/chunk_view/outer_iterator/operator*|accesses the element|notes={{mark c++23}}}} | ||
{{dsc mem fun|cpp/ranges/chunk_view/outer_iterator/operator_inc|title=operator++|increments the iterator|notes={{mark c++23}}}} | {{dsc mem fun|cpp/ranges/chunk_view/outer_iterator/operator_inc|title=operator++|increments the iterator|notes={{mark c++23}}}} | ||
Line 32: | Line 32: | ||
{{dsc begin}} | {{dsc begin}} | ||
{{dsc fun|cpp/ranges/chunk_view/outer_iterator/operator_cmp|title=operator==|compares the iterator with {{lt|cpp/iterator/default_sentinel_t|default sentinel}}|notes={{mark c++23}}}} | {{dsc fun|cpp/ranges/chunk_view/outer_iterator/operator_cmp|title=operator==|compares the iterator with {{lt|cpp/iterator/default_sentinel_t|default sentinel}}|notes={{mark c++23}}}} | ||
− | {{dsc fun|cpp/ranges/chunk_view/outer_iterator/operator-|title=operator-|calculates the number of chunks | + | {{dsc fun|cpp/ranges/chunk_view/outer_iterator/operator-|title=operator-|calculates the number of chunks |notes={{mark c++23}}}} |
{{dsc end}} | {{dsc end}} | ||
Line 42: | Line 42: | ||
===Example=== | ===Example=== | ||
{{example | {{example | ||
− | |||
|code= | |code= | ||
− | |||
#include <iostream> | #include <iostream> | ||
#include <iterator> | #include <iterator> | ||
− | |||
#include <ranges> | #include <ranges> | ||
+ | |||
int main() | int main() | ||
Line 61: | Line 59: | ||
++outer_iter) | ++outer_iter) | ||
{ | { | ||
− | auto chunk = *outer_iter; // chunk is | + | auto chunk = *outer_iter; // chunk is object of type |
// chunk_view::outer_iterator::value_type | // chunk_view::outer_iterator::value_type | ||
std::cout << '['; | std::cout << '['; | ||
Line 91: | Line 89: | ||
===References=== | ===References=== | ||
{{ref std c++23}} | {{ref std c++23}} | ||
− | {{ref std|title=Class | + | {{ref std|title=Class chunk_view::outer-iterator|id=range.chunk.outer.iter|section=26.7.28.3}} |
{{ref std end}} | {{ref std end}} | ||
Latest revision as of 22:43, 17 October 2023
class /*outer-iterator*/ |
(since C++23) (exposition only*) |
|
The return type of chunk_view::begin
if V
models input_range
.
Contents |
[edit] Member types
Member type | Definition |
iterator_concept
|
std::input_iterator_tag |
difference_type
|
ranges::range_difference_t<V> |
[edit] Data members
Member object | Definition |
parent_ (private)
|
A pointer to the "parent object" of type ranges::chunk_view* (exposition-only member object*) |
[edit] Member functions
(C++23) |
constructs an iterator (public member function) |
(C++23) |
move assigns another iterator (public member function) |
(C++23) |
accesses the element (public member function) |
(C++23) |
increments the iterator (public member function) |
[edit] Non-member functions
(C++23) |
compares the iterator with default sentinel (function) |
(C++23) |
calculates the number of chunks remaining (function) |
[edit] Nested classes
(C++23) |
the value type of /*output-iterator*/ (public member class) |
[edit] Example
Run this code
#include <iostream> #include <iterator> #include <ranges> #include <sstream> int main() { const std::string source{"ABCDEFGHIJ"}; auto letters = std::istringstream{source}; auto chunks = std::ranges::istream_view<char>(letters) | std::views::chunk(4); for (auto outer_iter = chunks.begin(); outer_iter != std::default_sentinel; ++outer_iter) { auto chunk = *outer_iter; // chunk is an object of type // chunk_view::outer_iterator::value_type std::cout << '['; for (auto inner_iter = chunk.begin(); inner_iter != std::default_sentinel; ++inner_iter) std::cout << *inner_iter; std::cout << "] "; } std::cout << '\n'; // The same output using range-for loops auto letters2 = std::istringstream{source}; auto chunks2 = std::ranges::istream_view<char>(letters2) | std::views::chunk(4); for (auto chunk : chunks2) { std::cout << '['; for (auto ch : chunk) std::cout << ch; std::cout << "] "; } std::cout << '\n'; }
Output:
[ABCD] [EFGH] [IJ] [ABCD] [EFGH] [IJ]
[edit] References
- C++23 standard (ISO/IEC 14882:2024):
- 26.7.28.3 Class chunk_view::outer-iterator [range.chunk.outer.iter]