Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::swappable,std::swappable_with

      From cppreference.com
      <cpp‎ |concepts
       
       
      Concepts library
       
      Defined in header<concepts>
      template<class T>

      concept swappable=
          requires(T& a, T& b){
             ranges::swap(a, b);

         };
      (1)(since C++20)
      template<class T,class U>

      concept swappable_with=
         std::common_reference_with<T, U>&&
          requires(T&& t, U&& u){
             ranges::swap(std::forward<T>(t),std::forward<T>(t));
             ranges::swap(std::forward<U>(u),std::forward<U>(u));
             ranges::swap(std::forward<T>(t),std::forward<U>(u));
             ranges::swap(std::forward<U>(u),std::forward<T>(t));

         };
      (2)(since C++20)

      The conceptswappable<T> specifies that lvalues of typeT are swappable.

      The conceptswappable_with<T, U> specifies that expressions of the type and value category encoded byT andU are swappable with each other.swappable_with<T, U> is satisfied only if a call toranges::swap(t, u) exchanges the value oft andu, that is, given distinct objectst2 equal tot andu2 equal tou, after evaluating eitherranges::swap(t, u) orranges::swap(u, t),t2 is equal tou andu2 is equal tot.

      [edit]Equality preservation

      Expressions declared inrequires expressions of the standard library concepts are required to beequality-preserving (except where stated otherwise).

      [edit]References

      • C++23 standard (ISO/IEC 14882:2024):
      • 18.4.9 Conceptswappable [concept.swappable]
      • C++20 standard (ISO/IEC 14882:2020):
      • 18.4.9 Conceptswappable [concept.swappable]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/concepts/swappable&oldid=177888"

      [8]ページ先頭

      ©2009-2025 Movatter.jp