Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/container/mdspan/swap2"

From cppreference.com
< cpp‎ | container‎ | mdspan
m (fmt.)
m (~links.)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{cpp/title|swap(std::mdspan)}}
+
{{title|swap{{small|(std::mdspan)}}}}
 
{{cpp/container/mdspan/navbar}}
 
{{cpp/container/mdspan/navbar}}
  
{{ddcl|header=mdspan|since=c++23|
+
{{ddcl|since=c++23|
 
friend constexpr void swap( mdspan& x, mdspan& y ) noexcept;
 
friend constexpr void swap( mdspan& x, mdspan& y ) noexcept;
 
}}
 
}}
  
Overloads the {{lc|std::swap}} algorithm for {{lc|std::mdspan}}. Exchanges the state of {{c|x}} with that of {{c|y}}.
+
Overloads the {{ltt|cpp/utility/swap|std::swap}} algorithm for {{rlpt|/|std::mdspan}}. Exchanges the state of {{c|x}} with that of {{c|y}}. Equivalent to:
  
Given {{tti|ptr_}}, {{tti|map_}}, and {{tti|acc_}} as exposition-only {{rlp|/#Data members|data members}}, equivalent to:
+
{{box|
{{source|
+
{{c/core|std::}}{{ltt|cpp/utility/swap}}{{c/core|(x.}}{{rlpsi|/#acc_}}{{c/core|, y.}}{{rlpsi|/#acc_}}{{c/core|);}}<br>
std::swap(x.ptr_, y.ptr_);
+
{{c/core|std::}}{{ltt|cpp/utility/swap}}{{c/core|(x.}}{{rlpsi|/#map_}}{{c/core|, y.}}{{rlpsi|/#map_}}{{c/core|);}}<br>
std::swap(x.map_, y.map_);
+
{{c/core|std::}}{{ltt|cpp/utility/swap}}{{c/core|(x.}}{{rlpsi|/#ptr_}}{{c/core|, y.}}{{rlpsi|/#ptr_}}{{c/core|);}}
std::swap(x.acc_, y.acc_);
+
 
}}
 
}}
 +
 +
{{cpp/hidden friend|{{tt|std::mdspan}}}}
  
 
===Parameters===
 
===Parameters===
Line 24: Line 25:
  
 
===Example===
 
===Example===
{{example|code=
+
{{example
 +
|code=
 
|output=
 
|output=
 
}}
 
}}

Latest revision as of 15:13, 18 October 2024

 
 
 
 
friend constexpr void swap( mdspan& x, mdspan& y ) noexcept;
(since C++23)

Overloads the std::swap algorithm for std::mdspan. Exchanges the state of x with that of y. Equivalent to:

std::swap(x.acc_, y.acc_);
std::swap(x.map_, y.map_);
std::swap(x.ptr_, y.ptr_);

This function is not visible to ordinary unqualified or qualified lookup, and can only be found by argument-dependent lookup when std::mdspan is an associated class of the arguments.

Contents

[edit] Parameters

x, y - mdspan objects whose states to swap

[edit] Return value

(none)

[edit] Example

[edit] See also