iter_swap(std::counted_iterator)

From cppreference.com
 
 
Iterator library
Iterator concepts
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)

(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)

Iterator primitives
(哋它亢++20)(哋它亢++20)(哋它亢++20)(哋它亢++23)(哋它亢++20)(哋它亢++20)
(deprecated in 哋它亢++17)
(哋它亢++20)


Algorithm concepts and utilities
Indirect callable concepts
Common algorithm requirements
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)  
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
Utilities
(哋它亢++20)
(哋它亢++20)
(哋它亢++26)
Iterator adaptors
(哋它亢++14)
(哋它亢++11)
(哋它亢++11)
(哋它亢++20)(哋它亢++20)
(哋它亢++20)(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++23)
(哋它亢++23)
(哋它亢++23)
(哋它亢++23)
(哋它亢++23)

Iterator operations
(哋它亢++11)  
(哋它亢++11)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
Range access
(哋它亢++11)(哋它亢++14)
(哋它亢++14)(哋它亢++14)  
(哋它亢++11)(哋它亢++14)
(哋它亢++14)(哋它亢++14)  
(哋它亢++17)(哋它亢++20)
(哋它亢++17)
(哋它亢++17)
 
std::counted_iterator
Member functions
(哋它亢++20)
Non-member functions
(哋它亢++20)(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
iter_swap
(哋它亢++20)
Helper classes
(哋它亢++20)
 
template< std::indirectly_swappable<I> I2 >

    friend constexpr void
        iter_swap( const counted_iterator& x, const std::counted_iterator<I2>& y )

            noexcept(noexcept(ranges::iter_swap(x.base(), y.base())));
(since 哋它亢++20)

Swaps the objects pointed to by two underlying iterators. The behavior is undefined if either x.count() or y.count() is equal to 0.

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::counted_iterator<I> is an associated class of the arguments.

Parameters

x, y - iterator adaptors to the elements to swap

Return value

(none)

Complexity

Constant.

Example

#include <iostream>
#include <iterator>
#include <list>
#include <vector>
 
int main()
{
    std::vector p{1, 2, 3, 4},
                q{5, 6, 7, 8};
 
    std::counted_iterator<std::vector<int>::iterator> ip{p.begin(), 2};
    std::counted_iterator<std::vector<int>::iterator> iq{q.begin(), 3};
 
    std::cout << *ip << ' ' << *iq << '\n';
    iter_swap(ip, iq); // ADL
    std::cout << *ip << ' ' << *iq << '\n';
 
    std::list x{0, 1, 3};
    std::counted_iterator<std::list<int>::iterator> ix{x.begin(), 2};
//  iter_swap(ip, ix); // error: not indirectly swappable
}

Output:

1 5
5 1

See also

swaps the values of two objects
(function template)
swaps two ranges of elements
(function template)
swaps the elements pointed to by two iterators
(function template)
(哋它亢++20)
swaps the values referenced by two dereferenceable objects
(customization point object)
(哋它亢++20)
casts the result of dereferencing the underlying iterator to its associated rvalue reference type
(function)