std::counte...erator::base(3)
π NAME π
std::counted_iterator::base - std::counted_iterator::base π«Ά
okay so this is the std::counted_iterator::base(3) page, and the manual name folded in near the top is C++ Standard Libary (spelled exactly like that in the header, no cap, we love a typo moment π
).
πΈ Synopsis πΈ
constexpr const I& base() const& noexcept; (1) (since C++20)
constexpr I base() &&; (2) (since C++20)
Returns the underlying base iterator. That's the whole vibe π¦
- Returns a reference to the underlying iterator.
- Move constructs the return value from the underlying iterator.
β¨ Parameters β¨
none. zero. not a single parameter, bestie β (none) π«Ά
π Return value π
- A reference to the underlying iterator.
- An iterator move constructed from the underlying iterator.
π₯ Exceptions π₯
May throw implementation-defined exceptions. so like, it may throw, and the implementation gets to define them β noted π
π Example π
// Run this code
#include <algorithm>
#include <iostream>
#include <iterator>
#include <type_traits>
#include <vector>
int main()
{
std::vector<int> v{0, 1, 2, 3, 4};
std::reverse_iterator<std::vector<int>::iterator>
reverse{v.rbegin()};
std::counted_iterator counted{reverse, 3};
static_assert(std::is_same<
decltype(counted.base()),
std::reverse_iterator<std::vector<int>::iterator> const&
>{});
std::cout << "Print with reverse_iterator: ";
for (auto r = counted.base(); r != v.rend(); ++r)
std::cout << *r << ' ';
std::cout << '\n';
std::cout << "Print with counted_iterator: ";
for (; counted != std::default_sentinel; ++counted)
std::cout << counted[0] << ' ';
std::cout << '\n';
}
πΊ Output: πΊ
Print with reverse_iterator: 4 3 2 1 0
Print with counted_iterator: 4 3 2
π§ Defect reports π§
The following behavior-changing defect reports were applied retroactively to previously published C++ standards. periodt.
- DR:
LWG 3391Β· Applied to:C++20Β· Behavior as published: the const version of base returns a copy of the underlying iterator Β· Correct behavior: returns a reference - DR:
LWG 3593Β· Applied to:C++20Β· Behavior as published: the const version of base returns a reference but might not be noexcept Β· Correct behavior: made noexcept
π See also π
operator*β accesses the pointed-to elementoperator->β (public member function) (C++20)countβ returns the distance to the end (C++20) (public member function)
sign-off cuteness: source is http://cppreference.com, date is 2024.06.10, and the footer page is std::counte...erator::base(3) β 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