std::counte...operator*,->(3)

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

πŸŽ€ std::counte...operator*,->(3) πŸŽ€

okay bestie, welcome to the C++ Standard Libary manual page for std::counted_iterator::operator*,-> β€” yes, the title is doing the absolute most, and we are keeping every character of it. periodt. πŸ’…

πŸ’– NAME πŸ’–

std::counted_iterator::operator*,-> β€” std::counted_iterator::operator*,->

like… it's giving "name so nice they said it twice," and honestly? iconic. ✨

🌸 Synopsis 🌸

okay so these are the three overloads, and they're all constexpr and all since C++20, no cap:

          constexpr decltype(auto) operator*();      (1) (since C++20)
          constexpr decltype(auto) operator*() const (2) (since C++20)
              requires /*dereferenceable*/<const I>;
          constexpr auto operator->() const noexcept (3) (since C++20)
              requires std::contiguous_iterator<I>;
  • (1), (2) β€” these return a reference to the current element. The behavior is undefined if this->count() <= 0. ⚠️ like bestie, do not test that, it's the danger zone. The function's body is equivalent to return *current;.
  • (3) β€” this one returns a pointer to the current element. The function's body is equivalent to return std::to_address(current);.

πŸ¦‹ Parameters πŸ¦‹

(none) β€” no arguments, no stress, we love that for us. 🫢

⭐ Return value ⭐

Reference or pointer to the current element. that's it, that's the vibe. πŸ’–

πŸ”₯ Example πŸ”₯

       // Run this code

        #include <complex>
        #include <iostream>
        #include <iterator>
        using std::operator""i;

        int main()
        {
            const auto il = {1.i, 2.i, 3.i, 4.i, 5.i};

            for (std::counted_iterator i{il.begin() + 1, 3}; i !=
       std::default_sentinel; ++i)
                std::cout << *i << ' ';
            std::cout << '\n';

            for (std::counted_iterator i{il.begin() + 1, 3}; i !=
       std::default_sentinel; ++i)
                std::cout << i->imag() << ' ';
            std::cout << '\n';
        }

πŸ–₯️ Output: πŸ–₯️

(0,2) (0,3) (0,4)
2 3 4

πŸ‘€ See also πŸ‘€

  • operator[] β€” accesses an element by index (C++20) (public member function)

shoutout to the source http://cppreference.com and the 2024.06.10 date stamp β€” mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from