iter_move(s...ve_iterator)(3)

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

πŸ’– iter_move(s...ve_iterator)(3) πŸ’–

okay bestie, welcome to the C++ Standard Library page for iter_move(s...ve_iterator)(3) β€” yes, that title is a whole mood. This is the std::move_iterator flavor of iter_move, and it's giving β€œI cast dereference results to rvalues” energy. πŸ’…

🌸 NAME 🌸

iter_move(std::move_iterator) - iter_move(std::move_iterator) β€” no cap, the NAME section is literally echoing itself, and honestly? iconic. πŸ‘‘

✨ SYNOPSIS ✨

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

Since C++20, bestie. This casts the result of dereferencing the underlying iterator to its associated rvalue reference type. πŸ¦‹

The function body is equivalent to this exact line: return std::ranges::iter_move(i.base()); β€” that's the whole move, periodt.

Important ADL tea: this function template is not visible to ordinary unqualified or qualified lookup, and can only be found by argument-dependent lookup when std::move_iterator<Iter> is an associated class of the arguments. iykyk. 🫢

πŸŽ€ PARAMETERS πŸŽ€

  • i β€” a source move iterator.

πŸ’œ RETURN VALUE πŸ’œ

An rvalue reference or a prvalue temporary. That's it, that's the return vibe. ✨

🧚 COMPLEXITY 🧚

Constant. ⭐

πŸ”₯ EXCEPTIONS πŸ”₯

noexcept specification: noexcept(noexcept(ranges::iter_move(i.base()))) β€” yes, it's conditionally noexcept, and the spec is right there in all its nested-noexcept glory. πŸ’€

πŸ“ EXAMPLE πŸ“

// 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{"Andromeda", "Cassiopeia", "Phoenix"}, q;

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

    using MI = std::move_iterator<std::vector<std::string>::iterator>;

    for (MI first{p.begin()}, last{p.end()}; first != last; ++first)
        q.emplace_back(/* ADL */ iter_move(first));

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

🌈 POSSIBLE OUTPUT 🌈

p[3] { "Andromeda", "Cassiopeia", "Phoenix" }
q[0] {  }
p[3] { "", "", "" }
q[3] { "Andromeda", "Cassiopeia", "Phoenix" }

πŸ‘‘ 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 adjusted 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 β€” yes bestie, that category label is doing exactly what it says on the tin. πŸŽ€


okay that's the whole page, bestie β€” sourced from cppreference.com, dated 2024.06.10, mwah πŸ’‹πŸ«Ά

πŸ“¦ where this page comes from