std::ranges...ter-iterator(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

✨ NAME ✨

std::ranges::chunk_view::outer-iterator β€” okay so this is the manual-name bestie, and the page is std::ranges...ter-iterator(3) from the C++ Standard Libary (yes, β€œLibary” is literally how the manual spells it πŸ’€). Say hi to std::ranges::chunk_view::outer-iterator β€” and yes, the NAME line is literally std::ranges::chunk_view::outer-iterator twice with a dash, because the manual is extra like that. It’s the exposition-only star of the show, bestie. πŸ’…

🌸 Synopsis 🌸

class /*outer-iterator*/  (since C++23)
                          (exposition only*)

It’s the return type of chunk_view::begin if V models input_range. That’s the whole vibe check, no cap. πŸ’–

πŸŽ€ Member types πŸŽ€

  • iterator_concept β€” std::input_iterator_tag
  • difference_type β€” ranges::range_difference_t<V>

πŸ¦‹ Data members πŸ¦‹

  • parent_ (private) β€” a pointer to the "parent object" of type ranges::chunk_view* (exposition-only member object*).

πŸ’… Member functions πŸ’…

  • constructor (C++23) β€” constructs an iterator; public member function.
  • operator= (C++23) β€” move assigns another iterator; public member function.
  • operator* (C++23) β€” accesses the element; public member function.
  • operator++ (C++23) β€” increments the iterator; public member function.

πŸ”₯ Non-member functions πŸ”₯

  • operator== (C++23) β€” compares the iterator with default sentinel; function.
  • operator- (C++23) β€” calculates the number of chunks remaining; function.

πŸŽ€ Nested classes πŸŽ€

  • value_type (C++23) β€” the value type of /*output-iterator*/; public member class.

🌈 Example 🌈

// Run this code β€” copy-paste bestie, it’s right here:

// 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 πŸ‘€

No extra entries listed here, bestie β€” the footer info is the little sign-off below. πŸ’–


Sign-off time: source/version is http://cppreference.com, date is 2024.06.10, and the page title is std::ranges...ter-iterator(3). That’s the whole manual page, and it ate. πŸ’…βœ¨

πŸ“¦ where this page comes from