<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2408: SFINAE-friendly common_type/iterator_traits is missing in C++14</title>
<meta property="og:title" content="Issue 2408: SFINAE-friendly common_type/iterator_traits is missing in C++14">
<meta property="og:description" content="C++ library issue. Status: C++17">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2408.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="2408"><a href="lwg-defects.html#2408">2408</a>. SFINAE-friendly <code>common_type/iterator_traits</code> is missing in C++14</h3>
<p><b>Section:</b> 21.3.9.7 <a href="https://wg21.link/meta.trans.other">[meta.trans.other]</a>, 24.3.2.3 <a href="https://wg21.link/iterator.traits">[iterator.traits]</a> <b>Status:</b> <a href="lwg-active.html#C++17">C++17</a>
 <b>Submitter:</b> Daniel Kr&uuml;gler <b>Opened:</b> 2014-06-19 <b>Last modified:</b> 2017-07-30</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View all other</b> <a href="lwg-index.html#meta.trans.other">issues</a> in [meta.trans.other].</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>
During the Rapperswil meeting the proposal <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4041.html">N4041</a>
had been discussed and there seemed to be strong consensus to apply the SFINAE-friendly definitions
that currently exist within the fundamentals-ts to the C++ Standard working draft. This issue requests this change to happen.
</p>


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

<ol>
<li><p>Change 21.3.9.7 <a href="https://wg21.link/meta.trans.other">[meta.trans.other]</a> p3 as indicated:</p>

<blockquote>
<p>
-3- <ins>For the <code>common_type</code> trait applied to a parameter pack <code>T</code> of types, 
the member <code>type</code> shall be either defined or not present as follows:</ins>
<ul>
<li><p><ins>If <code>sizeof...(T)</code> is zero, there shall be no member <code>type</code>.</ins></p></li>
<li><p><ins>If <code>sizeof...(T)</code> is one, let <code>T0</code> denote the sole type comprising <code>T</code>. 
The member typedef <code>type</code> shall denote the same type as <code>decay_t&lt;T0&gt;</code>.</ins></p></li>
<li><p><ins>If <code>sizeof...(T)</code> is greater than one, let <code>T1</code>, <code>T2</code>, and <code>R</code>, 
respectively, denote the first, second, and (pack of) remaining types comprising <code>T</code>. 
[<i>Note</i>: <code>sizeof...(R)</code> may be zero. &mdash; <i>end note</i>] Finally, let <code>C</code> denote 
the type, if any, of an unevaluated conditional expression (7.6.16 <a href="https://wg21.link/expr.cond">[expr.cond]</a>) whose first operand is an arbitrary value 
of type <code>bool</code>, whose second operand is an xvalue of type <code>T1</code>, and whose third operand is 
an xvalue of type <code>T2</code>. If there is such a type <code>C</code>, the member typedef <code>type</code> shall 
denote the same type, if any, as <code>common_type_t&lt;C,R...&gt;</code>. Otherwise, there shall be no member 
<code>type</code>.</ins></p></li>
</ul>
<del>The nested typedef <code>common_type::type</code> shall be defined as follows:</del>
</p>
<blockquote>
<pre>
<del>template &lt;class ...T&gt; struct common_type;

template &lt;class T&gt;
struct common_type&lt;T&gt; {
  typedef decay_t&lt;T&gt; type;
};

template &lt;class T, class U&gt;
struct common_type&lt;T, U&gt; {
  typedef decay_t&lt;decltype(true ? declval&lt;T&gt;() : declval&lt;U&gt;())&gt; type;
};

template &lt;class T, class U, class... V&gt;
struct common_type&lt;T, U, V...&gt; {
  typedef common_type_t&lt;common_type_t&lt;T, U&gt;, V...&gt; type;
};</del>
</pre>
</blockquote>
</blockquote>
</li>

<li><p>Change 24.3.2.3 <a href="https://wg21.link/iterator.traits">[iterator.traits]</a> p2 as indicated:</p>

<blockquote>
<p>
-2- The template <code>iterator_traits&lt;Iterator&gt;</code> <del>is defined as</del><ins>shall have 
the following as publicly accessible members, and have no other members, if and only if 
<code>Iterator</code> has valid (13.10.3 <a href="https://wg21.link/temp.deduct">[temp.deduct]</a>) member types <code>difference_type</code>, 
<code>value_type</code>, <code>pointer</code>, <code>reference</code>, and <code>iterator_category</code>; otherwise, 
the template shall have no members:</ins>
</p>
<blockquote>
<pre>
<del>namespace std {
  template&lt;class Iterator&gt; struct iterator_traits {</del>
    typedef typename Iterator::difference_type difference_type;
    typedef typename Iterator::value_type value_type;
    typedef typename Iterator::pointer pointer;
    typedef typename Iterator::reference reference;
    typedef typename Iterator::iterator_category iterator_category;
  <del>};
}</del>
</pre>
</blockquote>
</blockquote>
</li>
</ol>





</body>
</html>
