Files
hustoj/web/cppreference-zh/chmhelp/cpp-container-queue-swap2.html
2025-08-01 12:57:54 +08:00

120 lines
7.7 KiB
HTML

<!DOCTYPE html>
<html lang="zh" dir="ltr" class="client-nojs" xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh">
<head><meta http-equiv="x-ua-compatible" content="ie=edge">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>std::swap(std::queue)</title>
<link rel="stylesheet" href="ext.css" />
<link rel="stylesheet" href="site_modules.css" />
</head>
<body class="mediawiki ltr sitedir-ltr ns-0 ns-subject page-cpp_container_queue_swap2 skin-cppreference2 action-view cpp-page-template cpp-navbar">
<div id="cpp-content-base">
<div id="content"><a id="top"></a>
<h1 id="firstHeading" class="firstHeading"><span style="font-size:0.7em; line-height:130%">std::</span>swap<small>(std::queue)</small></h1>
<div id="bodyContent">
<div id="contentSub"><span class="subpages">&lt; <a href="cpp.html">cpp</a>&lrm; | <a href="cpp-container.html">container</a>&lrm; | <a href="cpp-container-queue.html">queue</a></span></div>
<div id="mw-content-text" lang="zh" dir="ltr" class="mw-content-ltr" xml:lang="zh">
<div class="t-page-template" style="">
<p></p>
</div>
<table class="t-dcl-begin">
<tbody>
<tr class="t-dsc-header">
<td>
<div>&#23450;&#20041;&#20110;&#22836;&#25991;&#20214; <code><a href="cpp-header-queue.html">&lt;queue&gt;</a></code></div>
</td>
<td></td>
<td></td>
</tr>
</tbody>
<tbody class="t-dcl-rev">
<tr class="t-dcl t-since-cxx11 t-until-cxx17">
<td>
<div><span class="mw-geshi cpp source-cpp"><span class="kw1">template</span><span class="sy1">&lt;</span> <span class="kw1">class</span> T, <span class="kw1">class</span> Container <span class="sy1">&gt;</span><br /></span>
<p><span class="kw4">void</span> swap<span class="br0">(</span> <a href="cpp-container-queue.html"><span class="kw1298">std::<span class="me2">queue</span></span></a><span class="sy1">&lt;</span>T,Container<span class="sy1">&gt;</span><span class="sy3">&amp;</span> lhs,<br /></p>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<a href="cpp-container-queue.html"><span class="kw1298">std::<span class="me2">queue</span></span></a><span class="sy1">&lt;</span>T,Container<span class="sy1">&gt;</span><span class="sy3">&amp;</span> rhs <span class="br0">)</span><span class="sy4">;</span></div>
</td>
<td class="t-dcl-nopad"></td>
<td><span class="t-mark-rev t-since-cxx11">(C++11 &#36215;)</span><br />
<span class="t-mark-rev t-until-cxx17">(C++17 &#21069;)</span></td>
</tr>
<tr class="t-dcl t-since-cxx17">
<td>
<div><span class="mw-geshi cpp source-cpp"><span class="kw1">template</span><span class="sy1">&lt;</span> <span class="kw1">class</span> T, <span class="kw1">class</span> Container <span class="sy1">&gt;</span><br /></span>
<p><span class="kw4">void</span> swap<span class="br0">(</span> <a href="cpp-container-queue.html"><span class="kw1298">std::<span class="me2">queue</span></span></a><span class="sy1">&lt;</span>T,Container<span class="sy1">&gt;</span><span class="sy3">&amp;</span> lhs,<br /></p>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<a href="cpp-container-queue.html"><span class="kw1298">std::<span class="me2">queue</span></span></a><span class="sy1">&lt;</span>T,Container<span class="sy1">&gt;</span><span class="sy3">&amp;</span> rhs <span class="br0">)</span> <span class="kw1">noexcept</span><span class="br0">(</span><span class="coMULTI">/* see below */</span><span class="br0">)</span><span class="sy4">;</span></div>
</td>
<td class="t-dcl-nopad"></td>
<td><span class="t-mark-rev t-since-cxx17">(C++17 &#36215;)</span></td>
</tr>
</tbody>
<tbody>
<tr class="t-dcl-sep">
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
<p>&#20026; <span class="t-c"><span class="mw-geshi cpp source-cpp"><a href="cpp-container-queue.html"><span class="kw1298">std::<span class="me2">queue</span></span></a></span></span> &#29305;&#21270; <span class="t-lc"><a href="cpp-algorithm-swap.html">std::swap</a></span> &#31639;&#27861;&#12290;&#20132;&#25442; <code>lhs</code> &#19982; <code>rhs</code> &#30340;&#20869;&#23481;&#12290;&#35843;&#29992; <span class="t-c"><span class="mw-geshi cpp source-cpp">lhs.<span class="me1">swap</span><span class="br0">(</span>rhs<span class="br0">)</span></span></span> &#12290;</p>
<table class="t-rev-begin">
<tr class="t-rev t-since-cxx17">
<td>
<p>&#27492;&#37325;&#36733;&#20165;&#33509; <span class="t-c"><span class="mw-geshi cpp source-cpp"><a href="cpp-types-is_swappable.html"><span class="kw573">std::<span class="me2">is_swappable_v</span></span></a><span class="sy1">&lt;</span>Container<span class="sy1">&gt;</span></span></span> &#20026; <span class="t-c"><span class="mw-geshi cpp source-cpp"><span class="kw2">true</span></span></span> &#25165;&#21442;&#19982;&#37325;&#36733;&#20915;&#35758;&#12290;</p>
</td>
<td><span class="t-mark-rev t-since-cxx17">(C++17 &#36215;)</span></td>
</tr>
</table>
<h3><span class="mw-headline" id=".E5.8F.82.E6.95.B0">&#21442;&#25968;</span></h3>
<table class="t-par-begin">
<tr class="t-par">
<td>lhs, rhs</td>
<td>-</td>
<td>&#35201;&#20132;&#25442;&#20869;&#23481;&#30340;&#23481;&#22120;</td>
</tr>
</table>
<h3><span class="mw-headline" id=".E8.BF.94.E5.9B.9E.E5.80.BC">&#36820;&#22238;&#20540;</span></h3>
<p>&#65288;&#26080;&#65289;</p>
<h3><span class="mw-headline" id=".E5.A4.8D.E6.9D.82.E5.BA.A6">&#22797;&#26434;&#24230;</span></h3>
<p>&#19982;&#20132;&#25442;&#24213;&#23618;&#23481;&#22120;&#30456;&#21516;&#12290;</p>
<h3><span class="mw-headline" id=".E5.BC.82.E5.B8.B8">&#24322;&#24120;</span></h3>
<table class="t-rev-begin">
<tr class="t-rev t-since-cxx17">
<td>
<div class="t-noexcept-full"><a href="cpp-language-noexcept_spec.html"><tt>noexcept</tt></a> &#35828;&#26126;&#65306;&nbsp;&nbsp;
<div class="t-noexcept-box"><span class="t-cc"><span class="mw-geshi cpp source-cpp"><span class="kw1">noexcept</span><span class="br0">(</span><span class="kw1">noexcept</span><span class="br0">(</span>lhs.<span class="me1">swap</span><span class="br0">(</span>rhs<span class="br0">)</span><span class="br0">)</span><span class="br0">)</span></span></span></div>
</div>
</td>
<td><span class="t-mark-rev t-since-cxx17">(C++17 &#36215;)</span></td>
</tr>
</table>
<h3><span class="mw-headline" id=".E6.B3.A8.E8.A7.A3">&#27880;&#35299;</span></h3>
<p>&#23613;&#31649; <span class="t-lc"><a href="cpp-algorithm-swap.html">std::swap</a></span> &#23545;&#23481;&#22120;&#36866;&#37197;&#22120;&#30340;&#37325;&#36733;&#26159;&#22312; C++11 &#24341;&#20837;&#30340;&#65292; C++98 &#20013;&#24050;&#33021;&#29992; <span class="t-lc"><a href="cpp-algorithm-swap.html">std::swap</a></span> &#20132;&#25442;&#23481;&#22120;&#36866;&#37197;&#22120;&#12290;&#36825;&#31181; <span class="t-lc"><a href="cpp-algorithm-swap.html">std::swap</a></span> &#35843;&#29992;&#36890;&#24120;&#25317;&#26377;&#32447;&#24615;&#26102;&#38388;&#22797;&#26434;&#24230;&#65292;&#20294;&#21487;&#20197;&#25552;&#20379;&#26356;&#22909;&#30340;&#22797;&#26434;&#24230;&#12290;</p>
<h3><span class="mw-headline" id=".E7.A4.BA.E4.BE.8B">&#31034;&#20363;</span></h3>
<table class="metadata plainlinks ambox mbox-small-left ambox-notice" style="">
<tr>
<td class="mbox-empty-cell"></td>
<td class="mbox-text" style="">&#26412;&#33410;&#26410;&#23436;&#25104;<br />
&#21407;&#22240;&#65306;&#26242;&#26080;&#31034;&#20363;</td>
</tr>
</table>
<h3><span class="mw-headline" id=".E5.8F.82.E9.98.85">&#21442;&#38405;</span></h3>
<table class="t-dsc-begin">
<tr class="t-dsc">
<td>
<div class="t-dsc-member-div">
<div><a href="cpp-container-queue-swap.html"><span class="t-lines"><span>swap</span></span></a></div>
<div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span></span></div>
</div>
</td>
<td>&#20132;&#25442;&#20869;&#23481;<br />
<span class="t-mark">(&#20844;&#24320;&#25104;&#21592;&#20989;&#25968;)</span></td>
</tr>
</table>
</div>
<div class="visualClear"></div>
</div>
</div>
</div>
</body>
</html>