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

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

okay bestie, this is the std::ranges::chunk_view::inner-iterator(3) page from the C++ Standard Libary manual β€” section 3, C++23, exposition-only energy, and she is lowkey iconic. Let's unpack her together πŸ’…βœ¨

πŸ’– NAME πŸ’–

std::ranges::chunk_view::inner-iterator β€” and yes, the page says std::ranges::chunk_view::inner-iterator again, so we're keeping both, periodt.

🌸 Synopsis 🌸

Code vibe:

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

Translation for the group chat: this is the return type of chunk_view::outer-iterator::value_type::begin if V models input_range. That's the whole condition, no cap.

πŸŽ€ Member types πŸŽ€

  • iterator_concept β€” std::input_iterator_tag
  • difference_type β€” ranges::range_difference_t<V>
  • value_type β€” ranges::range_value_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)
  • base (C++23) β€” returns an iterator to the current element (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 remained number of elements (function)
  • iter_move (C++23) β€” casts the result of dereferencing the underlying iterator to its associated rvalue reference type (function)
  • iter_swap (C++23) β€” swaps the objects pointed to by two underlying iterators (function)

🌈 Example 🌈

Run this code πŸƒβ€β™€οΈπŸ’¨:

#include <iostream>
#include <iterator>
#include <ranges>
#include <sstream>

int main()
{
    auto letters = std::istringstream{"ABCDEFGHIJK"};

    auto chunks = std::ranges::istream_view<char>(letters)
                | std::views::chunk(4);

    for (auto chunk : chunks)
    {
        // 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';
}

πŸ“ Output πŸ“

[ABCD] [EFGH] [IJK]

🧚 References 🧚

  • C++23 standard (ISO/IEC 14882:2023):
    • 26.7.28.5 Class chunk_view::inner-iterator [range.chunk.inner.iter]

πŸ‘‘ See also πŸ‘‘

No extra SEE ALSO entries listed on this page, bestie β€” just the footer link situation below. πŸ’œ


Source/version: http://cppreference.com Β· date: 2024.06.10 Β· footer tag: std::ranges...ner-iterator(3) β€” that's the footer, and that's the whole vibe. bye bestie, go chunk responsibly πŸ’…πŸ«Ά

πŸ“¦ where this page comes from