iter_swap(s...ve_iterator)(3)

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

πŸ’… iter_swap(s...ve_iterator)(3) β€” C++ Standard Libary πŸ’…

okay so bestie, welcome to the iter_swap(std::move_iterator) page from the C++ Standard Libary β€” yes, that's the manual name up top, typo and all, I'm not touching it 😭. This is iterator friendship content, and honestly? It ate.

πŸ’– NAME πŸ’–

iter_swap(std::move_iterator) - iter_swap(std::move_iterator)

That's the whole name, bestie. It's the std::move_iterator flavor of iter_swap, and it said what it said. πŸ’…

πŸŒ€ Synopsis πŸŒ€

          template< std::indirectly_swappable<Iter> Iter2 >

              friend constexpr void
                  iter_swap( const move_iterator& x, const
       (since C++20)
          std::move_iterator<Iter2>& y )

                      noexcept(/*see below*/);

Swaps the objects pointed to by two underlying iterators. The function body is equivalent to ranges::iter_swap(x.base(), y.base());.

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.

πŸŽ€ Parameters πŸŽ€

  • x, y β€” move iterators to the elements to swap

✨ Return value ✨

(none). Yes, nothing. It's a side-effect main character. 🫢

πŸ”₯ Complexity πŸ”₯

Constant. That's the whole vibe.

πŸ’€ Exceptions πŸ’€

noexcept specification:

noexcept(noexcept(ranges::iter_swap(x.base(), y.base())))

🌸 Example 🌸

// Run this code β€” literally go run it:

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

        int main()
        {
            std::vector<std::string> p{"AA", "EE"},
                                     q{"ⱯⱯ", "ƎƎ"};

            std::move_iterator<std::vector<std::string>::iterator>
                x = std::make_move_iterator(p.begin()),
                y = std::make_move_iterator(q.begin());

            std::cout << *x << ' ' << *y << '\n';

            iter_swap(x, y); // ADL

            std::cout << *x << ' ' << *y << '\n';
        }

🌈 Output 🌈

        AA β±―β±―
        β±―β±― AA

πŸ¦‹ See also πŸ¦‹

  • swap β€” swaps the values of two objects (function template)
  • swap_ranges β€” swaps two ranges of elements (function template)
  • iter_swap β€” swaps the elements pointed to by two iterators (function template)
  • iter_swap β€” swaps the values referenced by two dereferenceable objects (C++20) (customization point object)
  • iter_swap β€” swaps the objects pointed to by two adjusted underlying iterators (C++20) (function template)

πŸ‘‘ Category πŸ‘‘

  • * conditionally noexcept

mwah πŸ’‹ this page comes from http://cppreference.com, dated 2024.06.10, and its footer tag is iter_swap(s...ve_iterator)(3) β€” periodt. 🫢

πŸ“¦ where this page comes from