Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::ranges::iter_swap

      From cppreference.com
      <cpp‎ |iterator
       
       
      Iterator library
      Iterator concepts
      Iterator primitives
      Algorithm concepts and utilities
      Indirect callable concepts
      Common algorithm requirements
      (C++20)
      (C++20)
      (C++20)
      Utilities
      (C++20)
      Iterator adaptors
      Iterator customization points
      ranges::iter_swap
      (C++20)
      Range access
      (C++11)(C++14)
      (C++14)(C++14)  
      (C++11)(C++14)
      (C++14)(C++14)  
      (C++17)(C++20)
      (C++17)
      (C++17)
       
      Defined in header<iterator>
      namespace ranges{

         inlinenamespace/* unspecified */{
             inlineconstexpr/* unspecified */
                  iter_swap=/* unspecified */;
         }

      }
      (since C++20)
      (customization point object)
      Call signature
      template<class I1,class I2>
      constexprvoid iter_swap( I1&& i1, I2&& i2)noexcept(/* see below */);
      (since C++20)
      Helper function
      template<class X,class Y>

      constexprstd::iter_value_t<X>
          iter-exchange-move( X&& x, Y&& y)
         noexcept(noexcept(std::iter_value_t<X>(std::ranges::iter_move(x)))&&

                   noexcept(*x= std::ranges::iter_move(y)));
      (exposition only*)

      Swaps values denoted by two iterators.

      The effect of the exposition-only helper functioniter-exchange-move is equivalent to

      std::iter_value_t<X> old(std::ranges::iter_move(x));*x= std::ranges::iter_move(y);return old;

      ranges::iter_swap(i1, i2) isexpression-equivalent to:

      1. (void)iter_swap(i1, i2), ifi1 ori2 has a class or enumeration type and the expression is well-formed, where theoverload resolution ofiter_swap is performed with the additional candidatevoid iter_swap(auto,auto)= delete;[1], excludingstd::ranges::iter_swap itself.
        • If the selected overload does not exchange the value denoted byi1 andi2, the program is ill-formed, no diagnostic required.
      2. Otherwise,ranges::swap(*i1,*i2) if bothI1 andI2 modelindirectly_readable and ifstd::iter_reference_t<I1> andstd::iter_reference_t<I2> modelswappable_with.
      3. Otherwise,(void)(*i1= iter-exchange-move(i2, i1)), ifstd::indirectly_movable_storable<I1, I2> andstd::indirectly_movable_storable<I2, I1> are both modeled, except thati1 is only evaluated once.
      4. Otherwise,ranges::iter_swap(i1, i2) is ill-formed, which can result insubstitution failure whenranges::iter_swap(i1, i2) appears in the immediate context of a template instantiation.
      1. This precludes calling unconstrainedstd::iter_swap.

      Customization point objects

      The nameranges::iter_swap denotes acustomization point object, which is a constfunction object of aliteralsemiregular class type. SeeCustomizationPointObject for details.

      [edit]Example

      This section is incomplete
      Reason: no example

      [edit]See also

      (C++20)
      swaps the objects pointed to by two adjusted underlying iterators
      (function template)[edit]
      (C++20)
      swaps the objects pointed to by two underlying iterators
      (function template)[edit]
      swaps the elements pointed to by two iterators
      (function template)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/iterator/ranges/iter_swap&oldid=156030"

      [8]ページ先頭

      ©2009-2025 Movatter.jp