std::ranges...erator::base(3)

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

🌸 std::ranges...erator::base(3) 🌸

hey bestie!! welcome to the C++ Standard Libary page for this one ✨ (yes, that's the manual name, and yes we're keeping it exactly as it appears πŸ’…). This is the std::ranges::transform_view::iterator::base member function, and it's giving "hand me the iterator underneath" 🫢.


πŸŽ€ NAME πŸŽ€

std::ranges::transform_view::iterator::base β€” std::ranges::transform_view::iterator::base.

That's the name twice, exactly like the manpage, and honestly? iconic πŸ’….

✨ Synopsis ✨

Two overloads, both iconic, both since C++20:

constexpr const ranges::iterator_t<Base>& base() const & noexcept;

(1) (since C++20)

constexpr ranges::iterator_t<Base> base() &&;

(2) (since C++20)

Returns the underlying iterator.

  1. Returns a reference to the underlying iterator.
  2. Move constructs the result from the underlying iterator.

🫢 Parameters 🫢

(none) β€” literally zero parameters, bestie πŸŽ€.

πŸ’– Return value πŸ’–

  1. A reference to the underlying iterator.
  2. An iterator move constructed from the underlying iterator.

πŸ¦‹ Example πŸ¦‹

// Run this code

#include <algorithm>
#include <iostream>
#include <iterator>
#include <ranges>

int main()
{
    const auto v = { 0, 1, 2, 3, 4 };
    auto x2 = [](int x) { return x << 1; };
    std::ranges::transform_view tv{ v, x2 };
    std::ostream_iterator<int> ostr{ std::cout, " " };

    std::ranges::copy(v, ostr), std::cout << '\n';
    std::ranges::copy(tv.base(), ostr), std::cout << '\n';
    std::ranges::copy(tv, ostr), std::cout << '\n';
}

πŸ“ Output πŸ“

0 1 2 3 4
0 1 2 3 4
0 2 4 6 8

πŸ’€ Defect reports πŸ’€

The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

  • DR LWG 3533, applied to C++20 β€” behavior as published: the const& overload 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& overload of base might not be noexcept; correct behavior: made noexcept.

mwah πŸ’‹ source/version: http://cppreference.com, date: 2024.06.10, page: std::ranges...erator::base(3). that's the footer folded into a cute little bye-bye, bestie 🫢✨

πŸ“¦ where this page comes from