std::counte...ator::count(3)
π std::counte...ator::count(3) π
okay bestie, welcome to the <std::counte...ator::count(3)> page from the C++ Standard Libary manual (yes, that spelling, no cap π
). This is the std::counted_iterator::count moment, and itβs giving very specific, very useful energy β¨.
π NAME π
std::counted_iterator::count - std::counted_iterator::count π«Ά
fr fr, the NAME line is literally echoing itself, and honestly? iconic.
β¨ Synopsis β¨
The signature is here, and itβs been serving since C++20:
constexpr std::iter_difference_t<I> count() const noexcept; (since
C++20)
So what does it do? It returns the underlying length that is the distance to the end. Thatβs the whole vibe check π.
π Parameters π
(none) β zero, zilch, not a single parameter, bestie π.
π¦ Return value π¦
The underlying length. Thatβs it. Thatβs the return value, periodt π .
πΈ Example πΈ
// Run this code β yes bestie, run it, itβs literally right there β¨
#include <cassert>
#include <iostream>
#include <iterator>
int main()
{
constexpr static auto il = {1, 2, 3, 4, 5};
constexpr std::counted_iterator i1{il.begin() + 1, 3};
static_assert(i1.count() == 3);
auto i2{i1};
for (; std::default_sentinel != i2; ++i2)
std::cout << "*i2: " << *i2 << ", count(): " << i2.count() <<
'\n';
assert(i2.count() == 0);
}
π₯ Output π₯
*i2: 2, count(): 3
*i2: 3, count(): 2
*i2: 4, count(): 1
look at that little count() countdown, absolutely ate π₯
π See also π
baseβ accesses the underlying iterator π (C++20) (public member function)
mwah π this iconic little page comes from http://cppreference.com, dated 2024.06.10, and its footer name is std::counte...ator::count(3). byeeee π«Άπ
π¦ 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