<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2367: pair and tuple are not correctly implemented for is_constructible with no args</title>
<meta property="og:title" content="Issue 2367: pair and tuple are not correctly implemented for is_constructible with no args">
<meta property="og:description" content="C++ library issue. Status: C++17">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2367.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#C++17">C++17</a> status.</em></p>
<h3 id="2367"><a href="lwg-defects.html#2367">2367</a>. <code>pair</code> and <code>tuple</code> are not correctly implemented for <code>is_constructible</code> with no args</h3>
<p><b>Section:</b> 21.3.6.4 <a href="https://wg21.link/meta.unary.prop">[meta.unary.prop]</a> <b>Status:</b> <a href="lwg-active.html#C++17">C++17</a>
 <b>Submitter:</b> Howard Hinnant <b>Opened:</b> 2014-02-19 <b>Last modified:</b> 2017-07-30</p>
<p><b>Priority: </b>3
</p>
<p><b>View other</b> <a href="lwg-index-open.html#meta.unary.prop">active issues</a> in [meta.unary.prop].</p>
<p><b>View all other</b> <a href="lwg-index.html#meta.unary.prop">issues</a> in [meta.unary.prop].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++17">C++17</a> status.</p>
<p><b>Discussion:</b></p>
<p>
Consider:
</p>
<blockquote><pre>
struct X
{
  X() = delete;
};

int main()
{
  typedef std::pair&lt;int, X&gt; P;
  static_assert(!std::is_constructible&lt;P&gt;::value, "");
  static_assert(!std::is_default_constructible&lt;P&gt;::value, "");
  typedef std::tuple&lt;int, X&gt; T;
  static_assert(!std::is_constructible&lt;T&gt;::value, "");
  static_assert(!std::is_default_constructible&lt;T&gt;::value, "");
}
</pre></blockquote>
<p>
For me these <code>static_asserts</code> fail. And worse than that, even asking the question fails (as opposed to gets the wrong answer):
</p>
<blockquote><pre>
assert(!std::is_constructible&lt;P&gt;::value);
</pre></blockquote>
<p>
In file included from test.cpp:2:
</p>
<blockquote><pre>
error:
      call to deleted constructor of 'X'
   pair() : first(), second() {}
                     ^
note: function has been explicitly marked deleted here
    X() = delete;
    ^
1 error generated.
</pre></blockquote>
<p>
This can be solved by specializing <code>is_constructible</code> on <code>pair</code> and <code>tuple</code> for zero Args:
</p>
<blockquote><pre>
template &lt;class T, class U&gt;
struct is_constructible&lt;pair&lt;T, U&gt;&gt;
  : integral_constant&lt;bool, is_default_constructible&lt;T&gt;::value &amp;&amp;
                            is_default_constructible&lt;U&gt;::value&gt;
{};

template &lt;class ...T&gt;
struct is_constructible&lt;tuple&lt;T...&gt;&gt;
  : integral_constant&lt;bool,
                      __all&lt;is_default_constructible&lt;T&gt;::value...&gt;::value&gt;
{};
</pre></blockquote>
<p>
Now everything just works.
</p>

<p><i>[2014-05-14, Daniel comments]</i></p>


<p>
The proposed resolution is incomplete, because it wouldn't work for <i>cv</i>-qualified objects of
<code>pair</code> or for references of them during reference-initialization.
<p/>
I would like to point out that the approach suggested in <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3739.html">N3739</a>
can be easily extended to solve the problem without need to muddle with specializing <code>is_constructible</code>:
</p>
<blockquote><pre>
template&lt;class U1 = T1, class U2 = T2,
  typename enable_if&lt;
    is_default_constructible&lt;U1&gt;::value &amp;&amp; is_default_constructible&lt;U2&gt;::value
  , bool&gt;::type = false
&gt;
constexpr pair();
</pre></blockquote>
<p>
The new wording proposal represents an alternative wording change that I would strongly prefer.
</p>

<strong>Previous resolution from Howard [SUPERSEDED]:</strong>
<p/>
<blockquote class="note">
<p>This wording is relative to N3936.</p>

<ol>
<li><p>Add to 22.3.3 <a href="https://wg21.link/pairs.spec">[pairs.spec]</a>:</p>

<blockquote>
<pre>
<ins>template &lt;class T, class U&gt;
struct is_constructible&lt;pair&lt;T, U&gt;&gt;
  : integral_constant&lt;bool, is_default_constructible&lt;T&gt;::value &amp;&amp;
                            is_default_constructible&lt;U&gt;::value&gt;
{};</ins>
</pre>
</blockquote>
</li>

<li><p>Add to 22.4.12 <a href="https://wg21.link/tuple.special">[tuple.special]</a>:</p>

<blockquote>
<pre>
<ins>template &lt;class ...T&gt;
struct is_constructible&lt;tuple&lt;T...&gt;&gt;
  : integral_constant&lt;bool, <i>see below</i>&gt;
{};</ins>
</pre>
<blockquote><p>
<ins>-?- The second argument to <code>integral_constant</code> shall be true if for each <code>T</code>, 
<code>is_default_constructible&lt;T&gt;::value</code> is true.</ins>
</p>
</blockquote>
</blockquote>
</li>
</ol>
</blockquote>

<p><i>[2015-05, Lenexa]</i></p>

<p>
STL: I object to this resolution due to British spelling of behavior<br/>
JW: we already have other places of this spelling<br/>
VV: the easy resolution is to remove the notes<br/>
MC: if that's all we want to change: put it in and make the editorial change of removing the note<br/>
VV: the other paper doesn't make any of these changes so it would be consistent<br/>
JW: this make me want even more the features of having constructors doing the Right Thing
- I haven't written up the request to do something like that<br/>
VV: so it would be an aggregate reflecting the properties of the constituting types<br/>
JW: I should write that up<br/>
MC: any objection to move to ready? in favor: 16, opposed: 0, abstain: 1 
</p>


<p id="res-2367"><b>Proposed resolution:</b></p>
<p>This wording is relative to N3936.</p>

<ol>
<li><p>Change 22.3.2 <a href="https://wg21.link/pairs.pair">[pairs.pair]</a> around p3 as indicated:</p>

<blockquote><pre>
constexpr pair();
</pre>
<blockquote>
<p>
<del>-3- <i>Requires</i>: <code>is_default_constructible&lt;first_type&gt;::value</code> is true and 
<code>is_default_constructible&lt;second_type&gt;::value</code> is true.</del>
<p/>
-4- <i>Effects</i>: Value-initializes first and second.
<p/>
<ins>-?- <i>Remarks</i>: This constructor shall not participate in overload resolution unless 
<code>is_default_constructible&lt;first_type&gt;::value</code> is true and 
<code>is_default_constructible&lt;second_type&gt;::value</code> is true. [<i>Note</i>: This behaviour can be implemented
by a constructor template with default template arguments &mdash; <i>end note</i>].</ins>
</p>
</blockquote>
</blockquote>
</li>

<li><p>Change 22.4.4.2 <a href="https://wg21.link/tuple.cnstr">[tuple.cnstr]</a> around p4 as indicated:</p>

<blockquote><pre>
constexpr tuple();
</pre>
<blockquote>
<p>
<del>-4- <i>Requires</i>: <code>is_default_constructible&lt;<i>T<sub>i</sub></i>&gt;::value</code> is true for all <i>i</i>.</del>
<p/>
-5- <i>Effects</i>: Value initializes each element.
<p/>
<ins>-?- <i>Remarks</i>: This constructor shall not participate in overload resolution unless 
<code>is_default_constructible&lt;<i>T<sub>i</sub></i>&gt;::value</code> is true for all <i>i</i>. [<i>Note</i>: This behaviour can 
be implemented by a constructor template with default template arguments &mdash; <i>end note</i>].</ins>
</p>
</blockquote>
</blockquote>
</li>
</ol>






</body>
</html>
