std::counte...operator*,->(3)
π 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 ifthis->count() <= 0. β οΈ like bestie, do not test that, it's the danger zone. The function's body is equivalent toreturn *current;.(3)β this one returns a pointer to the current element. The function's body is equivalent toreturn 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
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms