std::iter_m...se_iterator)(3)
π 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
- 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