<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 1078: DE-17: Remove class type_index</title>
<meta property="og:title" content="Issue 1078: DE-17: Remove class type_index">
<meta property="og:description" content="C++ library issue. Status: NAD Concepts">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue1078.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#NAD_Concepts">NAD Concepts</a> status.</em></p>
<h3 id="1078"><a href="lwg-closed.html#1078">1078</a>. DE-17: Remove class type_index</h3>
<p><b>Section:</b> 17.7.7 <a href="https://wg21.link/type.index">[type.index]</a> <b>Status:</b> <a href="lwg-active.html#NAD_Concepts">NAD Concepts</a>
 <b>Submitter:</b> Doug Gregor <b>Opened:</b> 2009-03-20 <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#type.index">issues</a> in [type.index].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#NAD Concepts">NAD Concepts</a> status.</p>
<p><b>Discussion:</b></p>

<p><b>Addresses DE 17</b></p>

<p>
DE-17: 
</p>
<p>
The class <code>type_index</code> should be removed; it provides no additional
functionality beyond providing appropriate concept maps.
</p>

<p><i>[
2009-03-31 Peter adds:
]</i></p>


<blockquote>
<p>
It is not true, in principle, that <code>std::type_index</code> provides no  utility
compared to bare <code>std::type_info*</code>.
</p>
<p>
<code>std::type_index</code> can avoid the lifetime issues with <code>type_info</code> when  the
DLL that has produced the <code>type_info</code> object is unloaded. A raw
<code>type_info*</code> does not, and cannot, provide any protection in this  case.
A <code>type_index</code> can (if the implementor so chooses) because it  can wrap a
smart (counted or even cloning) pointer to the <code>type_info</code>  data that is
needed for <code>name()</code> and <code>before()</code> to work.
</p>
</blockquote>



<p id="res-1078"><b>Proposed resolution:</b></p>
<p>Modify the header &lt;typeinfo&gt; synopsis in 
  17.7 <a href="https://wg21.link/support.rtti">[support.rtti]</a>p1 as follows:</p>

<blockquote><pre>
namespace std { 
  class type_info; 
  <del>class type_index;</del>
  template &lt;class T&gt; struct hash;
  template&lt;&gt; struct hash&lt;<del>type_index</del><ins>const type_info *</ins>&gt; : public std::unary_function&lt;<del>type_index</del><ins>const type_info *</ins>, size_t&gt; {
    size_t operator()(<del>type_index</del><ins>const type_info *</ins> <del>index</del><ins>t</ins>) const;
  }<ins>;</ins>
  <ins>concept_map LessThanComparable&lt;const type_info *&gt; <i>see below</i></ins>
  class bad_cast; 
  class bad_typeid;
}
</pre></blockquote>

<p>Add the following new subsection</p>
<blockquote>
<p>
<ins>18.7.1.1 Template specialization <code>hash&lt;const type_info *&gt;</code>
[type.info.hash]</ins></p>

<pre>
<ins>size_t operator()(const type_info *x) const;</ins>
</pre>
<ol>
<li><ins><i>Returns</i>: <code>x-&gt;hash_code()</code></ins></li>
</ol>
</blockquote>

 <p>Add the following new subsection</p>
 <blockquote>
<p><ins>18.7.1.2 <code>type_info</code> concept map [type.info.concepts]</ins></p>


<pre>
<ins>concept_map LessThanComparable&lt;const type_info *&gt; {</ins>
  <ins>bool operator&lt;(const type_info *x, const type_info *y) { return x-&gt;before(*y); }</ins>
  <ins>bool operator&lt;=(const type_info *x, const type_info *y) { return !y-&gt;before(*x); }</ins>
  <ins>bool operator&gt;(const type_info *x, const type_info *y) { return y-&gt;before(*x); }</ins>
  <ins>bool operator&gt;=(const type_info *x, const type_info *y) { return !x-&gt;before(*y); }</ins>
<ins>}</ins>
</pre>
<ol>
  <li><ins><i>Note</i>: provides a well-defined ordering among
  <code>type_info const</code> pointers, which makes such pointers
  usable in associative containers (23.4).</ins></li>
</ol>
</blockquote>

<p>Remove section 17.7.7 <a href="https://wg21.link/type.index">[type.index]</a></p>





</body>
</html>
