<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head>
    <title>'constexpr' feature macro concerns</title>
    <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
    <meta http-equiv="Content-Language" content="en-us">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

    <style type="text/css">
        .addition { color: green; }
        .right { float:right }
        .changed-deleted { background-color: #CFF0FC ; text-decoration: line-through; display: none; }
        .addition.changed-deleted { color: green; background-color: #CFF0FC ; text-decoration: line-through; text-decoration: black double line-through; display: none; }
        .changed-added { background-color: #CFF0FC ;}
        .notes { background-color: gold ;}
        pre { line-height: 1.2; font-size: 10pt; margin-top: 25px; }
        .desc { margin-left: 35px; margin-top: 10px; padding:0; white-space: normal; font-family:monospace }
        body {max-width: 1024px; margin-left: 25px;}
        del { background-color: red; }
        ins { background-color: lightgreen; }
        .lmargin50{margin-left: 50px;}
        .width_third{width: 33%;}
        .cppkeyword { color: blue; }
        .asmcostly { color: red; }
        .cppcomment { color: green; }
        .cppcomment > .cppkeyword{ color: green; }
        .cpptext { color: #2E8B57; }
        .cppaddition { background-color: #CFC; }
        .cppdeletion {  text-decoration: line-through; background-color: #FCC; }
        .stdquote { background-color: #ECECEC; font-family: Consolas,monospace; }
    </style>
    </head>
    <body bgcolor="#ffffff">
    <address>Document number: P1424R1</address>
    <address>Project: Programming Language C++</address>
    <address>Audience: SG10, Library Working group</address>
    <address>&nbsp;</address>
    <address>Antony Polukhin &lt;<a href="mailto:antoshkka@gmail.com">antoshkka@gmail.com</a>&gt;, &lt;<a href="mailto:antoshkka@yandex-team.ru">antoshkka@yandex-team.ru</a>&gt;</address>
    <address>&nbsp;</address>
    <address>Date: 2019-04-25</address>
    <h1>'constexpr' feature macro concerns</h1>

    <h2>I. Quick Introduction</h2>
    <p>In <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1032r1.html">P1032R1 "Misc constexpr bits"</a> a feature testing macro <code>__cpp_lib_constexpr_misc</code> was proposed.</p>
    <p>That's not the best name for the macro. The name is not very informative. <code>__cpp_lib_constexpr_misc</code> also does not suite the needs of future constexprifications.</p>

    <p>This paper discuss different approaches for constexpr feature testing macro.</p>

    <h2>II. Approaches</h2>
    <h4>A. Single constexpr feature testing macro</h4>
    <p>Make a <code>__cpp_lib_constexpr</code> macro and increment its version on each new constexpr addition to the library.</p>
    <p>Pros:</p>
    <ul>
        <li>Simple to use and to remember</li>
    </ul>
    <p>Cons:</p>
    <ul>
        <li>Not vendor friendly - if there's a constexpr addition <i>A</i> followed by a constexpr addition <i>B</i> and <i>A</i> is hard to implement, then the vendor can not say that <i>B</i> is supported, even if it is implemented</li>
    </ul>


    <h4>B. Fuse constexpr feature testing into the feature testing macro of a component</h4>
    <p>Update the value of feature testing macro of a particular component. For example, update <code>_­_­cpp_­lib_­string_­view</code> with value <code>201811L</code> because <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1032r1.html">P1032R1 "Misc constexpr bits"</a> touched the <code>string_view</code>.</p>
    <p>Pros:</p>
    <ul>
        <li>Better granularity, more vendor friendly</li>
        <li>Simple to find</li>
    </ul>
    <p>Cons:</p>
    <ul>
        <li>Not many Standard library classes have their own feture testing macro. So with this approach each constexpr addition adds a bunch of feature testing macro to the [support.limits.general].</li>
    </ul>

    <h4>C. Have a feature testing macro per paper/proposal</h4>
    <p>This approach was taken by the <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1032r1.html">P1032R1</a> with its <code>__cpp_lib_constexpr_misc</code> macro.</p>
    <p>Pros:</p>
    <ul>
        <li>Simple to detect that the particular paper is implemented by vendor</li>
    </ul>
    <p>Cons:</p>
    <ul>
        <li>Not vendor friendly - paper could be very big and the implementor may wish to implement part of it right now, leaving the remaining parts for the next release.</li>
    </ul>

<h2>III. Conclusions</h2>
  <p>Each approach has its own advantages and disadvantages. I'd like recommend the following generic approach:</p>
  <ul>
      <li>Each new constexpr paper should have either a new feature testing macro or should update the existing one.</li>
      <li>Introduce a <code>__cpp_lib_constexpr</code> macro and increase it on each LWG constexpr paper adoption.</li>
      <li>Listen to the Standard Library developers and users. Add feature testing macro on their request.</li>
  </ul>


<h2>IV. LWG discussion</h2>
  <p>Discussion of the paper in Kona lead to the following conclusion: rename <code>__cpp_lib_constexpr_misc</code> to <code>__cpp_lib_constexpr</code> and bump the value on every change.</p>
  <p>Note that for a more generic feature testing macro we should include it in every header or just not include it in some subset of headers. Otherwise it would be surprising for
  users. For example if we increment the macro value for some constexpr additions in &lt;vector&gt; the macro will not be available via &lt;vector&gt; inclusion.</p>

<h2>V. Wording (relative to N4800)</h2>
  <p>Apply the following changes to the Table 36 "Standard library feature-test macros" in [support.limits.general]:</p>
  <table border="1"><tr><td><code>__cpp_lib_constexpr<del>_misc</del></code></td><td>201811L</td><td><del><code>&lt;array> &lt;functional&gt;
&lt;iterator&gt; &lt;string_view&gt;
&lt;tuple&gt; &lt;utility&gt;</code></del><ins>Any C++ library header from Table 19 or any C++ header for C library facilities from Table 20</ins></td></tr></table>

</body></html>

