table of contents
std::ranges::chunk_view::outer-iterator(3) | C++ Standard Libary | std::ranges::chunk_view::outer-iterator(3) |
NAME¶
std::ranges::chunk_view::outer-iterator - std::ranges::chunk_view::outer-iterator
Synopsis¶
class /*outer-iterator*/ (since C++23)
(exposition only*)
The return type of chunk_view::begin if V models input_range.
Member types¶
Member type Definition
iterator_concept std::input_iterator_tag
difference_type ranges::range_difference_t<V>
Data members
Member object Definition
parent_ (private) A pointer to the "parent object" of type
ranges::chunk_view*
(exposition-only member object*)
Member functions¶
constructor constructs an iterator
(C++23) (public member function)
operator= move assigns another iterator
(C++23) (public member function)
operator* accesses the element
(C++23) (public member function)
operator++ increments the iterator
(C++23) (public member function)
Non-member functions¶
operator== compares the iterator with default sentinel
(C++23) (function)
operator- calculates the number of chunks remaining
(C++23) (function)
Nested classes
value_type the value type of /*output-iterator*/
(C++23) (public member class)
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]
References¶
* C++23 standard (ISO/IEC 14882:2023):
* 26.7.28.3 Class chunk_view::outer-iterator [range.chunk.outer.iter]
See also¶
2024.06.10 | http://cppreference.com |