<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 1383: Inconsistent defaulted move&#47;copy members in pair and tuple</title>
<meta property="og:title" content="Issue 1383: Inconsistent defaulted move&#47;copy members in pair and tuple">
<meta property="og:description" content="C++ library issue. Status: Resolved">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue1383.html">
<meta property="og:type" content="website">
<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png">
<meta property="og:image:alt" content="C++ logo">
<style>
  p {text-align:justify}
  li {text-align:justify}
  pre code.backtick::before { content: "`" }
  pre code.backtick::after { content: "`" }
  blockquote.note
  {
    background-color:#E0E0E0;
    padding-left: 15px;
    padding-right: 15px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
  ins {background-color:#A0FFA0}
  del {background-color:#FFA0A0}
  table.issues-index { border: 1px solid; border-collapse: collapse; }
  table.issues-index th { text-align: center; padding: 4px; border: 1px solid; }
  table.issues-index td { padding: 4px; border: 1px solid; }
  table.issues-index td:nth-child(1) { text-align: right; }
  table.issues-index td:nth-child(2) { text-align: left; }
  table.issues-index td:nth-child(3) { text-align: left; }
  table.issues-index td:nth-child(4) { text-align: left; }
  table.issues-index td:nth-child(5) { text-align: center; }
  table.issues-index td:nth-child(6) { text-align: center; }
  table.issues-index td:nth-child(7) { text-align: left; }
  table.issues-index td:nth-child(5) span.no-pr { color: red; }
  @media (prefers-color-scheme: dark) {
     html {
        color: #ddd;
        background-color: black;
     }
     ins {
        background-color: #225522
     }
     del {
        background-color: #662222
     }
     a {
        color: #6af
     }
     a:visited {
        color: #6af
     }
     blockquote.note
     {
        background-color: rgba(255, 255, 255, .10)
     }
  }
</style>
</head>
<body>
<hr>
<p><em>This page is a snapshot from the LWG issues list, see the <a href="lwg-active.html">Library Active Issues List</a> for more information and the meaning of <a href="lwg-active.html#Resolved">Resolved</a> status.</em></p>
<h3 id="1383"><a href="lwg-defects.html#1383">1383</a>. Inconsistent defaulted move&#47;copy members in <code>pair</code> and <code>tuple</code></h3>
<p><b>Section:</b> 22.3 <a href="https://wg21.link/pairs">[pairs]</a>, 22.4 <a href="https://wg21.link/tuple">[tuple]</a> <b>Status:</b> <a href="lwg-active.html#Resolved">Resolved</a>
 <b>Submitter:</b> INCITS <b>Opened:</b> 2010-08-25 <b>Last modified:</b> 2016-01-28</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View all other</b> <a href="lwg-index.html#pairs">issues</a> in [pairs].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#Resolved">Resolved</a> status.</p>
<p><b>Discussion:</b></p>
<p><b>Addresses US-97</b></p>
<p>
<code>pair</code>'s class definition in N3092 22.3.2 <a href="https://wg21.link/pairs.pair">[pairs.pair]</a>
contains "<code>pair(const pair&amp;) = default;</code>" and 
"<code>pair&amp; operator=(pair&amp;&amp; p);</code>". The latter is described by
22.3.2 <a href="https://wg21.link/pairs.pair">[pairs.pair]</a> p.12-13.
<p/>
"<code>pair(const pair&amp;) = default;</code>" is a user-declared explicitly defaulted
copy constructor. According to  [class.copy]&#47;10, this inhibits 
the implicitly-declared move constructor. <code>pair</code> should be move constructible. 
( [class.copy]&#47;7 explains that "<code>pair(pair&lt;U, V&gt;&amp;&amp; p)</code>" 
will never be instantiated to move <code>pair&lt;T1, T2&gt;</code> to <code>pair&lt;T1, T2&gt;</code>.)<br/>
"<code>pair&amp; operator=(pair&amp;&amp; p);</code>" is a user-provided move
assignment operator (according to 9.6.2 <a href="https://wg21.link/dcl.fct.def.default">[dcl.fct.def.default]</a>&#47;4: "A 
special member function is user-provided if it is user-declared and not explicitly defaulted
on its first declaration."). According to  [class.copy]&#47;20, this inhibits
the implicitly-declared copy assignment operator. <code>pair</code>
should be copy assignable, and was in C++98&#47;03. (Again,
 [class.copy]&#47;7 explains that "<code>operator=(const pair&lt;U, V&gt;&amp; p)</code>" 
will never be instantiated to copy <code>pair&lt;T1, T2&gt;</code> to <code>pair&lt;T1, T2&gt;</code>.)<br/>
Additionally, "<code>pair&amp; operator=(pair&amp;&amp; p);</code>" is
unconditionally defined, whereas according to  [class.copy]&#47;25,
defaulted copy&#47;move assignment operators are defined as
deleted in several situations, such as when non-static data
members of reference type are present.
<p/>
If "<code>pair(const pair&amp;) = default;</code>" and "<code>pair&amp; operator=(pair&amp;&amp; p);</code>" 
were removed from <code>pair</code>'s class definition in 22.3.2 <a href="https://wg21.link/pairs.pair">[pairs.pair]</a> and from 
22.3.2 <a href="https://wg21.link/pairs.pair">[pairs.pair]</a>&#47;12-13, <code>pair</code> would
receive implicitly-declared copy&#47;move constructors and
copy&#47;move assignment operators, and  [class.copy]&#47;25 would
apply. The implicitly-declared copy&#47;move constructors
would be trivial when <code>T1</code> and <code>T2</code> have trivial copy&#47;move
constructors, according to  [class.copy]&#47;13, and similarly for the
assignment operators, according to [class.copy]&#47;27. Notes could
be added as a reminder that these functions would be
implicitly-declared, but such notes would not be necessary
(the Standard Library specification already assumes a
high level of familiarity with the Core Language, and
casual readers will simply assume that <code>pair</code> is copyable
and movable).
<p/>
Alternatively, <code>pair</code> could be given explicitly-defaulted
copy&#47;move constructors and copy&#47;move assignment
operators. This is a matter of style.
<p/>
<code>tuple</code> is also affected. <code>tuple</code>'s class definition in 22.4 <a href="https://wg21.link/tuple">[tuple]</a> contains:
</p>
<pre>
tuple(const tuple&amp;) = default;
tuple(tuple&amp;&amp;);
tuple&amp; operator=(const tuple&amp;);
tuple&amp; operator=(tuple&amp;&amp;);
</pre>
<p>
They should all be removed or all be explicitly-defaulted,
to be consistent with <code>pair</code>. Additionally, 22.4.4.2 <a href="https://wg21.link/tuple.cnstr">[tuple.cnstr]</a>&#47;8-9 specifies the 
behavior of an explicitly defaulted function, which is currently inconsistent with
<code>pair</code>.
</p>
<p><i>[
Resolution proposed by ballot comment:
]</i></p>

<blockquote><p>
Either remove "<code>pair(const pair&amp;) = default;</code>" and
"<code>pair&amp; operator=(pair&amp;&amp; p);</code>" from <code>pair</code>'s class
definition in  22.3.2 <a href="https://wg21.link/pairs.pair">[pairs.pair]</a> and from  22.3.2 <a href="https://wg21.link/pairs.pair">[pairs.pair]</a> p.12-13, or
give pair explicitly-defaulted copy&#47;move constructors and copy&#47;move assignment operators.<br/>
Change <code>tuple</code> to match.
</p></blockquote>

<p><i>[
2010-10-24 Daniel adds:
]</i></p>


<blockquote><p>
Accepting <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3140.html">n3140</a> would solve this issue:
The move&#47;copy constructor will be defaulted, but the corresponding assignment operators need a non-default implementation
because they are supposed to work for references as well.
</p></blockquote>



<p id="res-1383"><b>Proposed resolution:</b></p><p>
See <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3140.html">n3140</a>.
</p>




</body>
</html>
