std::move_iterator::base(3)
π NAME π
std::move_iterator::base - std::move_iterator::base. Bestie, this is the std::move_iterator::base(3) page from the C++ Standard Libary manual, and it's literally about pulling the underlying base iterator back out of a std::move_iterator. The function returns the underlying base iterator. Periodt. π
β¨ Synopsis β¨
Here's the overload lineup, exactly as the standard girly says:
iterator_type base() const;
constexpr iterator_type base() const;
constexpr const iterator_type& base() const& noexcept;
constexpr iterator_type base() &&;
iterator_type base() const;β since C++11, until C++17.constexpr iterator_type base() const;β overload (1), since C++17, until C++20.constexpr const iterator_type& base() const& noexcept;β since C++20.constexpr iterator_type base() &&;β overload (2), since C++20.
Overload (1): until C++20 it copy constructs the return value from the underlying iterator; since C++20 it returns a reference to the underlying iterator. Overload (2) move constructs the return value from the underlying iterator. π¦
πΈ Parameters πΈ
(none). Zero parameters. No arguments. It's giving "nothing to see here, just vibes." π«Ά
π Return value π
- 1) until C++20: a copy of the underlying iterator.
- 1) since C++20: a reference to the underlying iterator.
- 2) an iterator move constructed from the underlying iterator. β¨
π Exceptions π
May throw implementation-defined exceptions. That's the whole tea. Implementation-defined, bestie β not a promise that nothing throws. π
π Example π
// Run this code
#include <algorithm>
#include <iostream>
#include <iterator>
#include <vector>
int main()
{
std::vector<int> v{0, 1, 2, 3, 4};
std::move_iterator<std::vector<int>::reverse_iterator>
m1{v.rbegin()},
m2{v.rend()};
std::copy(m1.base(), m2.base(),
std::ostream_iterator<int>(std::cout, " "));
std::cout << '\n';
}
π Output π
4 3 2 1 0
π¦ Defect reports π¦
The following behavior-changing defect reports were applied retroactively to previously published C++ standards. The glow-up history:
LWG 3391, applied to C++20: behavior as published β theconstversion ofbasereturns a copy of the underlying iterator; correct behavior β returns a reference. πLWG 3593, applied to C++20: behavior as published β theconstversion ofbasereturns a reference but might not benoexcept; correct behavior β madenoexcept. β¨
π See also π
operator*β accesses the pointed-to element (public member function) (C++11).operator->β accesses the pointed-to element (public member function) (C++11)(deprecated in C++20).
Source/version and date, bestie: http://cppreference.com, 2024.06.10. Stay slaying your iterators ππβ¨
π¦ 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