std::iter_m...se_iterator)(3)

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

πŸ’– std::iter_move(std::reverse_iterator) πŸ’–

okay so bestie, we're in the C++ Standard Libary manual and this page is for std::iter_move(std::reverse_iterator). It's giving niche C++20 hidden-friend energy, and we're gonna get through it together. 🫢


πŸ’… NAME πŸ’…

std::iter_move(std::reverse_iterator) β€” std::iter_move(std::reverse_iterator). Yes, the NAME section really says it twice. The manpage said it, not me. πŸ’€

πŸ¦‹ Synopsis πŸ¦‹

          friend constexpr std::iter_rvalue_reference_t<Iter>
              iter_move( const std::reverse_iterator& i ) noexcept(/* see below
       (since C++20)
          */);

It casts the result of dereferencing the adjusted underlying iterator into its associated rvalue reference type. ✨

The function body is equivalent to this exact little snack:

        auto tmp = i.base();
        return std::ranges::iter_move(--tmp);
Big vibe check: this function template is not visible to ordinary unqualified or qualified lookup, and can only be found by argument-dependent lookup when std::reverse_iterator<Iter> is an associated class of the arguments. 🫢

πŸŽ€ Parameters πŸŽ€

  • i β€” a source reverse iterator

🌸 Return value 🌸

You get an rvalue reference or a prvalue temporary.

⭐ Complexity ⭐

Constant.

πŸ”₯ Exceptions πŸ”₯

The noexcept specification is literally this:

          noexcept(

              std::is_nothrow_copy_constructible_v<Iter> &&
              noexcept(std::ranges::iter_move(--std::declval<Iter&>()))

          )

🧚 Example 🧚

okay this example is a whole little code adventure. Copy it exactly, bestie:

       // Run this code

        #include <iomanip>
        #include <iostream>
        #include <iterator>
        #include <string>
        #include <vector>

        void print(auto const& rem, auto const& v)
        {
            std::cout << rem << '[' << size(v) << "] {";
            for (char comma[]{0, 0}; auto const& s : v)
                std::cout << comma << ' ' << std::quoted(s), comma[0] = ',';
            std::cout << " }\n";
        }

        int main()
        {
            std::vector<std::string> p{"Alpha", "Bravo", "Charlie"}, q;

            print("p", p), print("q", q);

            using RI =
       std::reverse_iterator<std::vector<std::string>::iterator>;

            for (RI iter{p.rbegin()}, rend{p.rend()}; iter != rend; ++iter)
                q.emplace_back(/* ADL */ iter_move(iter));

            print("p", p), print("q", q);
        }

🌈 Possible output 🌈

        p[3] { "Alpha", "Bravo", "Charlie" }
        q[0] { }
        p[3] { "", "", "" }
        q[3] { "Charlie", "Bravo", "Alpha" }

πŸ‘‘ See also πŸ‘‘

  • iter_move (C++20) β€” casts the result of dereferencing an object to its associated rvalue reference type (customization point object)
  • iter_move (C++20) β€” casts the result of dereferencing the underlying iterator to its associated rvalue reference type (function)
  • move (C++11) β€” obtains an rvalue reference (function template)
  • move_if_noexcept (C++11) β€” obtains an rvalue reference if the move constructor does not throw (function template)
  • forward (C++11) β€” forwards a function argument (function template)
  • ranges::move (C++20) β€” moves a range of elements to a new location (niebloid)
  • ranges::move_backward (C++20) β€” moves a range of elements to a new location in backwards order (niebloid)

🏷️ Category 🏷️

  • conditionally noexcept

catch u later, bestie πŸ’œ β€” source: http://cppreference.com, version/date: 2024.06.10, page: std::iter_m...se_iterator)(3) πŸ’…

πŸ“¦ where this page comes from