<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 1080: Concept ArithmeticLike should provide explicit boolean  conversion</title>
<meta property="og:title" content="Issue 1080: Concept ArithmeticLike should provide explicit boolean  conversion">
<meta property="og:description" content="C++ library issue. Status: NAD Concepts">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue1080.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="1080"><a href="lwg-closed.html#1080">1080</a>. Concept ArithmeticLike should provide explicit boolean  conversion</h3>
<p><b>Section:</b> 99 [concept.arithmetic] <b>Status:</b> <a href="lwg-active.html#NAD_Concepts">NAD Concepts</a>
 <b>Submitter:</b> Daniel Kr&uuml;gler <b>Opened:</b> 2009-03-21 <b>Last modified:</b> 2016-01-28</p>
<p><b>Priority: </b>Not Prioritized
</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>
Astonishingly, the current concept ArithmeticLike as specified in
99 [concept.arithmetic] does not provide explicit conversion
to <code>bool</code> although this is a common property of arithmetic types
(7.3.15 <a href="https://wg21.link/conv.bool">[conv.bool]</a>). Recent proposals that introduced such types
(integers of arbitrary precision,
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2143.pdf">n2143</a>,
decimals
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2732.pdf">n2732</a>
indirectly
via conversion to <code>long long</code>) also took care of such a feature.
</p>
<p>
Adding such an explicit conversion associated function would also
partly solve a currently invalid effects clause in library, which bases
on this property, 24.3.5.7 <a href="https://wg21.link/random.access.iterators">[random.access.iterators]</a>/2:
</p>
<blockquote><pre>
{ difference_type m = n;
 if (m &gt;= 0) while (m--) ++r;
 else while (m++) --r;
 return r; }
</pre></blockquote>

<p>
Both while-loops take advantage of a contextual conversion to <code>bool</code>
(Another problem is that the &gt;= comparison uses the no
longer supported existing implicit conversion from <code>int</code> to <code>IntegralLike</code>).
</p>

<p><b>Original proposed resolution:</b></p>
<ol>
<li>
<p>
In 99 [concept.arithmetic], add to the list of less refined
concepts one further concept:
</p>

<blockquote><pre>
concept ArithmeticLike&lt;typename T&gt;
  : Regular&lt;T&gt;, LessThanComparable&lt;T&gt;, HasUnaryPlus&lt;T&gt;, HasNegate&lt;T&gt;,
    HasPlus&lt;T, T&gt;, HasMinus&lt;T, T&gt;, HasMultiply&lt;T, T&gt;, HasDivide&lt;T, T&gt;,
    HasPreincrement&lt;T&gt;, HasPostincrement&lt;T&gt;, HasPredecrement&lt;T&gt;,
    HasPostdecrement&lt;T&gt;,
    HasPlusAssign&lt;T, const T&amp;&gt;, HasMinusAssign&lt;T, const T&amp;&gt;,
    HasMultiplyAssign&lt;T, const T&amp;&gt;,
    HasDivideAssign&lt;T, const T&amp;&gt;<ins>, ExplicitlyConvertible&lt;T, bool&gt;</ins> {
</pre></blockquote>
</li>
<li>
<p>
In 24.3.5.7 <a href="https://wg21.link/random.access.iterators">[random.access.iterators]</a>/2 change the current effects clause
as indicated [The proposed insertion fixes the problem that the previous
implicit construction from integrals has been changed to an explicit
constructor]:
</p>
<blockquote><pre>
{ difference_type m = n;
 if (m &gt;= <ins>difference_type(</ins>0<ins>)</ins>) while (m--) ++r;
 else while (m++) --r;
 return r; }
</pre></blockquote>
</li>
</ol>

<p><i>[
Batavia (2009-05):
]</i></p>

<blockquote>
<p>
We agree that arithmetic types ought be convertible to <code>bool</code>,
and we therefore agree with the proposed resolution's paragraph 1.
</p>
<p>
We do not agree that the cited effects clause is invalid,
as it expresses intent rather than specific code.
</p>
<p>
Move to Review, pending input from concepts experts.
</p>
</blockquote>



<p id="res-1080"><b>Proposed resolution:</b></p>
<p>
In 99 [concept.arithmetic], add to the list of less refined
concepts one further concept:
</p>

<blockquote><pre>
concept ArithmeticLike&lt;typename T&gt;
  : Regular&lt;T&gt;, LessThanComparable&lt;T&gt;, HasUnaryPlus&lt;T&gt;, HasNegate&lt;T&gt;,
    HasPlus&lt;T, T&gt;, HasMinus&lt;T, T&gt;, HasMultiply&lt;T, T&gt;, HasDivide&lt;T, T&gt;,
    HasPreincrement&lt;T&gt;, HasPostincrement&lt;T&gt;, HasPredecrement&lt;T&gt;,
    HasPostdecrement&lt;T&gt;,
    HasPlusAssign&lt;T, const T&amp;&gt;, HasMinusAssign&lt;T, const T&amp;&gt;,
    HasMultiplyAssign&lt;T, const T&amp;&gt;,
    HasDivideAssign&lt;T, const T&amp;&gt;<ins>, ExplicitlyConvertible&lt;T, bool&gt;</ins> {
</pre></blockquote>





</body>
</html>
