<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 388: Use of complex as a key in associative containers</title>
<meta property="og:title" content="Issue 388: Use of complex as a key in associative containers">
<meta property="og:description" content="C++ library issue. Status: NAD">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue388.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">NAD</a> status.</em></p>
<h3 id="388"><a href="lwg-closed.html#388">388</a>. Use of <code>complex</code> as a key in associative containers</h3>
<p><b>Section:</b> 29.4 <a href="https://wg21.link/complex.numbers">[complex.numbers]</a> <b>Status:</b> <a href="lwg-active.html#NAD">NAD</a>
 <b>Submitter:</b> Gabriel Dos Reis <b>Opened:</b> 2002-11-08 <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#complex.numbers">issues</a> in [complex.numbers].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#NAD">NAD</a> status.</p>
<p><b>Discussion:</b></p>
<p>
Practice with <code>std::complex&lt;&gt;</code> and the associative containers
occasionally reveals artificial and distracting issues with constructs
resembling: <code>std::set&lt;std::complex&lt;double&gt; &gt; s;</code>
</p>

<p>
The main reason for the above to fail is the absence of an appropriate
definition for <code>std::less&lt;std::complex&lt;T&gt; &gt;</code>. That in turn comes from
the definition of the primary template <code>std::less&lt;&gt;</code> in terms of
<code>operator&lt;</code>.
</p>

<p>
The usual argument goes as follows: Since there is no ordering over
the complex field compatible with field operations it makes little
sense to define a function <code>operator&lt;</code> operating on the datatype
<code>std::complex&lt;T&gt;</code>.  That is fine. However, that reasoning does not carry
over to <code>std::less&lt;T&gt;</code> which is used, among other things, by associative
containers as an ordering useful to meet complexity requirements.
</p>

<p>Related issue: <a href="lwg-closed.html#348" title="Minor issue with std::pair operator&lt; (Status: Dup)">348</a><sup><a href="https://cplusplus.github.io/LWG/issue348" title="Latest snapshot">(i)</a></sup>.</p>

<p><i>[
Pre Bellevue: Reopened at the request of Alisdair.
]</i></p>


<p><i>[
Bellevue:
]</i></p>


<blockquote><p>
This is a request for a design change, and not a defect in the standard.
It is in scope to consider, but the group feels that it is not a change
that we need to do. Is there a total ordering for floating point values,
including NaN? There is not a clear enough solution or big enough
problem for us to solve. Solving this problem would require solving the
problem for floating point, which is equally unclear. The LWG noted that
users who want to put objects into an associative container for which
<code>operator&lt;</code> isn't defined can simply provide their own comparison 
function object. NAD
</p></blockquote>


<p id="res-388"><b>Proposed resolution:</b></p>
<p>Informally: Add a specialization of <code>std::less</code> for <code>std::complex</code>.</p>


<p><b>Rationale:</b></p>
<p>Discussed in Santa Cruz.  An overwhelming majority of the LWG
believes this should not be treated a DR: it's a request for a design
change, not a defect in the existing standard.  Most people (10-3)
believed that we probably don't want this change, period: as with
issue <a href="lwg-closed.html#348" title="Minor issue with std::pair operator&lt; (Status: Dup)">348</a><sup><a href="https://cplusplus.github.io/LWG/issue348" title="Latest snapshot">(i)</a></sup>, it's hard to know where to draw the line.
The LWG noted that users who want to put objects into an associative
container for which <code>operator&lt;</code> isn't defined can simply
provide their own comparison function object.</p>





</body>
</html>
