Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/ranges/chunk view/outer iterator"

From cppreference.com
< cpp‎ | ranges‎ | chunk view
m (Example: +)
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}}.
 
+
Formed only if {{tt|V}} models {{lconcept|input_range}}.
+
 
+
The name of this class (shown here as {{c|/*outer-iterator*/}}) is unspecified.
+
 
+
===Data members===
+
Typical implementations of {{c|/*outer-iterator*/}} hold only one non-static data member – a pointer {{tti|parent_}} (the name is for exposition purposes only) to the "parent object", of type {{c|ranges::chunk_view*}}.
+
  
 
===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 remained|notes={{mark c++23}}}}
+
{{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
|A link to [https://godbolt.org/z/scE6f69cM Compiler Explorer]
 
 
|code=
 
|code=
#include <algorithm>
 
 
#include <iostream>
 
#include <iostream>
 
#include <iterator>
 
#include <iterator>
#include <sstream>
 
 
#include <ranges>
 
#include <ranges>
 +
  
 
int main()
 
int main()
Line 61: Line 59:
 
         ++outer_iter)
 
         ++outer_iter)
 
     {
 
     {
         auto chunk = *outer_iter; // chunk is and object of type
+
         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 {{tt|chunk_view::''outer-iterator''}}|id=range.chunk.outer.iter|section=26.7.28.3}}
+
{{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

 
 
Ranges library
Range adaptors
 
std::ranges::chunk_view
Member functions
Classes for input_ranges
Deduction guides
outer-iterator
outer-iterator::value_type
inner-iterator
 
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

constructs an iterator
(public member function)
(C++23)
move assigns another iterator
(public member function)
(C++23)
accesses the element
(public member function)
increments the iterator
(public member function)

[edit] Non-member functions

compares the iterator with default sentinel
(function)
(C++23)
calculates the number of chunks remaining
(function)

[edit] Nested classes

the value type of /*output-iterator*/
(public member class)

[edit] Example

#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]

[edit] See also