std::move_iterator::base(3)

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

πŸŽ€ 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 β€” the const version of base returns a copy of the underlying iterator; correct behavior β€” returns a reference. πŸ’…
  • 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 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