<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC
    "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN"
    "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">
<html xml:lang='en' xmlns:svg='http://www.w3.org/2000/svg' xmlns='http://www.w3.org/1999/xhtml'>
<head><meta content='application/xhtml+xml;charset=utf-8' http-equiv='Content-type' /><title>Wording for bool_constant, revision 1</title></head>
<body><!-- maruku -o bool_constant.html bool_constant.md --><style type='text/css'>
pre code { display: block; margin-left: 2em; }
div { display: block; margin-left: 2em; }
ins { text-decoration: underline; background-color: #A0FFA0 }
del { text-decoration: line-through; background-color: #FFA0A0 }
table.std { border: 1pt solid black; border-collapse: collapse; width: 70%; }
table.std td { border-bottom: 1pt solid black; vertical-align: text-top; }
</style><table><tbody>
<tr><th>Doc. no.:</th>	<td>N4389</td></tr>
<tr><th>Date:</th>	<td>2015-02-23</td></tr>
<tr><th>Project:</th>	<td>Programming Language C++, Library Working Group</td></tr>
<tr><th>Revises:</th>	<td>N4334</td></tr>
<tr><th>Reply-to:</th>	<td>Zhihao Yuan &lt;zy at miator dot net&gt;</td></tr>
</tbody></table>
<h1 id='wording_for_bool_constant_revision_1'>Wording for bool_constant, revision 1</h1>

<p>Rationale see <a href='https://issues.isocpp.org/show_bug.cgi?id=51'>https://issues.isocpp.org/show_bug.cgi?id=51</a>.</p>

<p>This paper consolidates <a href='http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2014/n4334.html'>N4334</a> with LWG&#8217;s wording improvements to <code>&lt;ratio&gt;</code>.</p>

<p>This wording is relative to N4296.</p>

<p>Modify 20.10.2 &#91;meta.type.synop&#93;:</p>

<pre><code>namespace std {
  // 20.10.3, helper class:
  template &lt;class T, T v&gt; struct integral_constant;</code></pre>
<div>
<ins><tt>
      template &lt;bool B&gt;<br />
      using bool_constant = integral_constant&lt;bool, B&gt;;<br />
      &nbsp;<br />
</tt></ins>
<del><tt>
      typedef integral_constant&lt;bool, true&gt; true_type;<br />
      typedef integral_constant&lt;bool, false&gt; false_type;<br />
</tt></del>
<ins><tt>
      typedef bool_constant&lt;true&gt; true_type;<br />
      typedef bool_constant&lt;false&gt; false_type;<br />
</tt></ins>
</div>
<blockquote>
<p>&#8230;</p>
</blockquote>

<p>Modify 20.10.3 &#91;meta.help&#93;:</p>

<pre><code>namespace std {
  template &lt;class T, T v&gt;
  struct integral_constant {</code></pre>

<blockquote>
<p>&#8230;</p>
</blockquote>

<pre><code>  };</code></pre>
<div>
<del><tt>
      typedef integral_constant&lt;bool, true&gt; true_type;<br />
      typedef integral_constant&lt;bool, false&gt; false_type;<br />
</tt></del>
</div>
<pre><code>}</code></pre>

<blockquote>
<p>The class template <code>integral_constant</code><ins>, alias template
<tt>bool_constant</tt>,</ins> and its associated typedefs <code>true_type</code> and <code>false_type</code> are used as base classes to define the interface for various type traits.</p>
</blockquote>

<p>Modify Table 49 in 20.10.4.3 &#91;meta.unary.prop&#93;:</p>
<div>
<table class='std'><tbody>
<tr>
<td style='width: 40%'>
<tt>
template &lt;class T&gt;<br />
struct is_signed;<br />
</tt>
</td>
<td style='width: 30%'>
If <tt>is_arithmetic&lt;T&gt;::value</tt> is <tt>true</tt>, the same result as
<del><tt>integral_constant&lt;bool, T(-1) &lt; T(0)&gt;::value</tt></del>
<ins><tt>bool_constant&lt;T(-1) &lt; T(0)&gt;::value</tt></ins>
; otherwise, <tt>false</tt>
</td>
<td>
</td>
</tr>
<tr>
<td style='width: 40%'>
<tt>
template &lt;class T&gt;<br />
struct is_unsigned;<br />
</tt>
</td>
<td style='width: 30%'>
If <tt>is_arithmetic&lt;T&gt;::value</tt> is <tt>true</tt>, the same result as
<del><tt>integral_constant&lt;bool, T(0) &lt; T(-1)&gt;::value</tt></del>
<ins><tt>bool_constant&lt;T(0) &lt; T(-1)&gt;::value</tt></ins>
; otherwise, <tt>false</tt>
</td>
<td>
</td>
</tr>
</tbody></table>
</div>
<p>Modify 20.11.5 &#91;ratio.comparison&#93;:</p>

<pre><code>template &lt;class R1, class R2&gt; struct ratio_equal</code></pre>
<div>
<del><tt>
      : integral_constant&lt;bool, <i>see below</i>&gt; { };<br />
</tt></del>
<ins><tt>
      : bool_constant&lt;R1::num == R2::num &amp;&amp;
R1::den == R2::den&gt; { };<br />
</tt></ins>
</div>
<blockquote><del>
If <tt>R1::num == R2::num</tt> and <tt>R1::den == R2::den</tt>,
<tt>ratio_equal&lt;R1, R2&gt;</tt>
shall be derived from
<tt>integral_constant&lt;bool, true&gt;</tt>
; otherwise it shall be derived from
<tt>integral_constant&lt;bool, false&gt;</tt>
.
</del></blockquote>

<pre><code>template &lt;class R1, class R2&gt; struct ratio_not_equal</code></pre>
<div>
<del><tt>
      : integral_constant&lt;bool,
      !ratio_equal&lt;R1, R2&gt;::value&gt; { };<br />
</tt></del>
<ins><tt>
      : bool_constant&lt;!ratio_equal&lt;R1, R2&gt;::value&gt; { };<br />
</tt></ins>
</div>
<pre><code>template &lt;class R1, class R2&gt; struct ratio_less</code></pre>
<div>
<del><tt>
      : integral_constant&lt;bool, <i>see below</i>&gt; { };<br />
</tt></del>
<ins><tt>
      : bool_constant&lt;<i>see below</i>&gt; { };<br />
</tt></ins>
</div>
<blockquote>
<p>If <del><tt>R1::num * R2::den &lt; R2::num * R1::den</tt></del> <ins><tt>R1::num</tt> &times; <tt>R2::den</tt> is less than
<tt>R2::num</tt> &times; <tt>R1::den</tt></ins> , <code>ratio_less&lt;R1, R2&gt;</code> shall be derived from <del><tt>integral_constant&lt;bool, true&gt;</tt></del> <ins><tt>bool_constant&lt;true&gt;</tt></ins> ; otherwise it shall be derived from <del><tt>integral_constant&lt;bool, false&gt;</tt></del> <ins><tt>bool_constant&lt;false&gt;</tt></ins> . Implementations may use other algorithms to compute this relationship to avoid overflow. If overflow occurs, the program is ill-formed.</p>
</blockquote>
<div>
<del><tt>
  template &lt;class R1, class R2&gt; struct ratio_less_equal<br />
    : integral_constant&lt;bool, !ratio_less&lt;R2, R1&gt;::value&gt; { };<br />
  template &lt;class R1, class R2&gt; struct ratio_greater<br />
    : integral_constant&lt;bool, ratio_less&lt;R2, R1&gt;::value&gt; { };<br />
  template &lt;class R1, class R2&gt; struct ratio_greater_equal<br />
    : integral_constant&lt;bool, !ratio_less&lt;R1, R2&gt;::value&gt; { };<br />
</tt></del>
<ins><tt>
  template &lt;class R1, class R2&gt; struct ratio_less_equal<br />
    : bool_constant&lt;!ratio_less&lt;R2, R1&gt;::value&gt; { };<br />
  template &lt;class R1, class R2&gt; struct ratio_greater<br />
    : bool_constant&lt;ratio_less&lt;R2, R1&gt;::value&gt; { };<br />
  template &lt;class R1, class R2&gt; struct ratio_greater_equal<br />
    : bool_constant&lt;!ratio_less&lt;R1, R2&gt;::value&gt; { };<br />
</tt></ins>
</div>
<h2 id='acknowledgments'>Acknowledgments</h2>

<p>Thanks Tony Van Eerd for bringing this to the reflector.</p>
</body></html>
