<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta http-equiv="Content-Style-Type" content="text/css" />
  <meta name="generator" content="pandoc" />
  <title>Standard Library Concepts - </title>
  <style type="text/css">code{white-space: pre;}</style>
  <link href="data:text/css;charset=utf-8,body%0A%7B%0Afont%2Dfamily%3A%20arial%2C%20sans%2Dserif%3B%0Amax%2Dwidth%3A%206%2E5in%3B%0Amargin%3A%200px%20auto%3B%0Afont%2Dsize%3A%2085%25%3B%0A%7D%0Ains%20%7Bbackground%2Dcolor%3A%20%23CCFFCC%3B%20text%2Ddecoration%3A%20none%3B%7D%0Adel%20%7Bbackground%2Dcolor%3A%20%23FFCACA%3B%20text%2Ddecoration%3A%20none%3B%7D%0Apre%20%7Bbackground%2Dcolor%3A%20%23D7EEFF%3B%20font%2Dsize%3A%2095%25%3B%20font%2Dfamily%3A%20%22courier%20new%22%2C%20courier%2C%20serif%3B%7D%0Acode%20%7Bfont%2Dsize%3A%20110%25%3B%20font%2Dfamily%3A%20%22courier%20new%22%2C%20courier%2C%20serif%3B%7D%0Atable%20%7Bfont%2Dsize%3A%2090%25%3B%7D%0A%0A" rel="stylesheet" type="text/css" />
</head>
<body>
<table>
<tbody>
<tr class="odd">
<td align="left">Document Number:</td>
<td align="left">P0802R0</td>
</tr>
<tr class="even">
<td align="left">Date:</td>
<td align="left">2017-10-15</td>
</tr>
<tr class="odd">
<td align="left">Reply-to:</td>
<td align="left">Beman Dawes <code>&lt;bdawes at acm dot org&gt;</code></td>
</tr>
<tr class="even">
<td align="left"></td>
<td align="left">Nicolai Josuttis <code>&lt;nico at josuttis.de&gt;</code></td>
</tr>
<tr class="odd">
<td align="left"></td>
<td align="left">Walter E. Brown <code>&lt;webrown.cpp at gmail.com&gt;</code></td>
</tr>
<tr class="even">
<td align="left"></td>
<td align="left">Bob Steagall <code>&lt;bob.steagall.cpp at gmail.com&gt;</code></td>
</tr>
<tr class="odd">
<td align="left">Audience:</td>
<td align="left">Library, Library Evolution</td>
</tr>
</tbody>
</table>
<h1 id="applying-concepts-to-the-standard-library-r0">Applying Concepts to the Standard Library [R0]</h1>
<h2 id="abstract">Abstract</h2>
<p>Questions are raised and recommendations made regarding how to best apply <a href="https://wg21.link/p0734r0">C++ Concepts</a> to the standard library. The most critical recommendation is that concepts for the standard library be based on the <a href="https://wg21.link/ranges"><em>Ranges TS</em></a> and adopted in two steps: fundamental concepts as soon as possible, followed by other <em>Ranges TS</em> library changes (a.k.a. STL2) at a more considered pace. Additional recommendation details, background, and rationale are given.</p>
<p>Caution: This is the initial version of this paper; it has not yet been reviewed by LEWG/LWG and its recommendations are subject to change. Updated revisions will be available at <a href="https://wg21.link/p0734">wg21.link/p0734</a>.</p>
<h2 id="background">Background</h2>
<p>The Library Extensions Working Group (LEWG) in Toronto asked for a white paper:</p>
<ul>
<li>How can <a href="https://wg21.link/p0734r0">C++ Concepts</a> best be applied to the standard library?</li>
<li>What policies should the LEWG and LWG define to guide and facilitate such adoption?</li>
<li>What questions about such adoption warrant further study?</li>
<li>What other actions are required to facilitate smooth adoption both by the committee and the broad C++ community?</li>
</ul>
<p>Walter Brown, Nico Josuttis, Bob Steagall, and Beman Dawes volunteered to lead this effort. Eric Niebler and Casey Carter were recruited for their <a href="https://wg21.link/ranges"><em>Ranges TS</em></a> expertise. <em>Right now, this paper represents purely the opinions of its authors. It is being circulated for feedback and suggestions from others to be incorporated in later drafts.</em></p>
<h2 id="big-picture-questions">Big Picture Questions</h2>
<h3 id="how-can-the-c-concepts-core-language-feature-be-best-applied-to-the-standard-library">How can the C++ Concepts core language feature be best applied to the standard library?</h3>
<ul>
<li><p>It seems clear that the basis for introducing concepts to the standard library must be the <a href="https://wg21.link/ranges"><em>Ranges TS</em></a>. That paper encapsulates the committee's knowledge and experience with fundamental library concepts and how these library concepts can be applied to improve the existing standard library. The <em>Ranges TS</em> has been implemented and exposed to the C++ community for several years; any other approach would be pure invention and speculation.</p></li>
<li><p>The <em>Ranges TS</em> has two separable components: a library of fundamental concepts (TS Clauses 6 &amp; 7), and revisions of existing library components (TS Clauses 8-12, also known as STL2). <strong>The characteristics of these two components are quite different, so they should be considered and adopted separately.</strong></p></li>
</ul>
<h3 id="recommendation-library-introduction">Recommendation: Library Introduction</h3>
<blockquote>
<p>Clause 20 of the WP, <em>Library introduction</em>, should be updated with <em>Ranges TS</em> clause 6 (<em>Library introduction</em>) and the related proposals and issues listed below as soon as a proposal can be prepared and processed by LEWG/LWG. We recommend that Jonathan Wakely and/or other LWG experts well-versed in writing library-wide standardese be recruited to lead this effort.</p>
</blockquote>
<p><strong>Rationale:</strong> <em>Library introduction</em> is where the standard mandates how the rest of the library is specified. Without the concept-related additions to <em>Library introduction</em>, adoption of concepts in the library would likely be inconsistent and chaotic.</p>
<p><strong>Related proposals:</strong></p>
<ul>
<li><a href="https://wg21.link/p0411">P0411</a> <em>Separating Library Requirements and Preconditions</em> by Jonathan Wakely.</li>
<li><a href="https://wg21.link/p0788">P0788</a> <em>Standard Library Specification in a Concepts and Contracts World</em> by Walter E. Brown.</li>
<li><a href="https://wg21.link/p0830">P0830</a> <em>Using Concepts and</em> <code>requires</code> <em>in the C++ Standard Library</em> by Nicolai Josuttis.</li>
</ul>
<p><strong>Specific issues:</strong></p>
<ul>
<li>Specify recommended or required conventions, such as &quot;use CamelCase for concepts&quot;.</li>
<li>Define policies for dealing with concepts that are not simply traits, such as &quot;concepts should be semantics-based, while traits are typically purely syntactic&quot;.</li>
<li>Describe any ABI breaks with concepts/requires. <em>Private email discussions need to be publicly summarized.</em></li>
</ul>
<h3 id="recommendation-fundamental-library-concepts">Recommendation: Fundamental Library Concepts</h3>
<blockquote>
<p><em>Ranges TS</em> clause 7 (<em>Concepts library</em>) should adopted by the C++20 WP as soon as a proposal can be prepared and processed by LEWG/LWG. We recommend that Casey Carter and Eric Niebler lead this effort and that they be given sufficient authority to include other fundamental material from the <em>Ranges TS</em>.</p>
</blockquote>
<p><strong>Rationale:</strong> The fundamental concepts are mature and well-known, as they are based on standard library requirements that have been developed and refined from C++98 onward. Because concepts are an entirely new core language feature, these fundamental concepts can be defined in the standard library without breaking any existing C++ code (modulo the usual namespace caveats). Furthermore, failure to standardize these fundamental concepts quickly is likely to result in proliferation of similar but subtly different user-supplied concepts, often with the same names. Confusion seems inevitable under such circumstances.</p>
<h3 id="recommendation-mitigate-stl2-user-code-breakage">Recommendation: Mitigate STL2 User-code Breakage</h3>
<blockquote>
<p>LEWG/LWG should develop a library breakage mitigation approach for STL2, as suggested in <a href="https://wg21.link/p0684">P0684</a>, before STL2 can be adopted into the standard library. We recommend that Titus Winters and Howard Hinnant lead this effort.</p>
</blockquote>
<p><strong>Rationale:</strong> The STL2 portion of the <em>Ranges TS</em> introduces numerous improvements over the traditional standard template library (STL). STL2 has the potential to break existing code because it does not exactly duplicate the current requirements of the standard library. Trying to duplicate the current library requirements is not desirable; they are too flawed, and trying to duplicate them exactly contributed to the failure of the C++11 concept effort. Furthermore, STL2 has not yet been deployed in large codebases, so the extent of code breakage is not yet known. In short, STL2 needs more real-world usage experience. Meanwhile, the LEWG/LWG must develop more concepts expertise and an appropriate library breakage mitigation policy, as described in <a href="https://wg21.link/p0684">P0684</a>, before STL2 can be integrated into the standard library. To do otherwise risks the stability of user codebases.</p>
<h3 id="recommendation-concepts-expertise-development">Recommendation: Concepts Expertise Development</h3>
<blockquote>
<p>LEWG/LWG members must increase their expertise and experience with the <em>Ranges TS</em>, as should the C++ community as a whole. Action plan and Leads needed.</p>
</blockquote>
<p><strong>Rationale:</strong> Currently the committee's expertise and experience with C++ concepts and the <em>Ranges TS</em> is concentrated in a small number of people, some of whom also have major commitments with other working groups. Yet the full application of concepts to the standard library is going to require significant effort from many people, both inside and outside the committee, if it is to happen reasonably quickly. Focusing attention on this need to build expertise and experience is done on the assumption that the first step in solving a need is to recognize that the need exists.</p>
<h3 id="recommendation-solicit-ranges-ts-user-feedback">Recommendation: Solicit <em>Ranges TS</em> User Feedback</h3>
<blockquote>
<p>LEWG/LWG must publicize the need for users to test their codebases, large and small, against the <a href="https://wg21.link/ranges"><em>Ranges TS</em></a> and report their results and impressions to the committee. Action plan and Leads needed.</p>
</blockquote>
<p><strong>Rationale:</strong> For reasons similar to those listed above, building expertise and gaining real-world experience using the <em>Ranges TS</em> from those outside the committee will provide crucial feedback to help shape the development of library policies regarding concepts.</p>
<h3 id="question-should-ts-clause-8-general-utilities-library-be-part-of-the-fundamental-concepts-proposal-or-the-stl2-proposal">Question: Should TS Clause 8, <em>General utilities library</em>, be part of the fundamental concepts proposal or the STL2 proposal?</h3>
<p><strong>To Be Decided</strong></p>
<h2 id="library-policies-for-adopting-c-concepts-into-the-standard-library">Library Policies for adopting C++ Concepts into the standard library</h2>
<p>The &quot;Big Picture&quot; section above aims at enabling the C++ Concepts framework for the standard library. This &quot;Library Policies&quot; section aims to establish library polices to guide C++ Concept usage in proposals for new library components, for modifying existing library components, and for resolving library issues.</p>
<h3 id="policy-build-the-foundations-for-concepts-first">Policy: Build the foundations for Concepts first</h3>
<blockquote>
<p>The standard library will adopt no uses of C++ Concepts until the <a href="#recommendation-library-introduction">Library Introduction</a> and <a href="#recommendation-fundamental-library-concepts">Fundamental Library Concepts</a> recommendations have been voted into the WP.</p>
</blockquote>
<p><strong>Rationale:</strong> This is similar to the current LWG/LEWG policy of not adopting use of a core language feature until that feature is actually voted into the WP. Similarly, it is unwise to adopt library motions that depend on library front-matter and fundamental library concepts until they are actually voted into the WP. This applies equally to new library components, existing components, and library issue resolutions.</p>
<h3 id="policy-specify-fundamental-library-concepts-where-applicable-in-new-library-components">Policy: Specify <a href="#recommendation-fundamental-library-concepts">fundamental library concepts</a> where applicable in new library components</h3>
<blockquote>
<p>New library components should specify <a href="#recommendation-fundamental-library-concepts">fundamental library concepts</a> rather than traditional requirements where applicable. As always, each library proposal is evaluated on its merits.</p>
</blockquote>
<p><strong>Rationale:</strong> There is usually no concern that new library components can break existing user code. The primary constraint on use of concepts in new library proposals is simply their lack of familiarity and limited compiler support. Both of these will be resolved as time passes.</p>
<h3 id="policy-new-library-components-may-introduce-new-c-concepts">Policy: New library components may introduce new C++ concepts</h3>
<blockquote>
<p>New library component proposals may define new concepts where appropriate. See <a href="https://wg21.link/p0557">How to design good concepts and use them well</a> by Bjarne Stroustrup. As always, each library proposal is evaluated on its merits. Proposal authors should be aware that defining many new concepts may initially cause delays in proposal evaluation and acceptance. As experience with concepts develops, the reverse may occur: it may become difficult to get proposals accepted unless they are specified in terms of concepts.</p>
</blockquote>
<h3 id="policy-apply-c-concepts-to-existing-library-components-with-great-caution">Policy: Apply C++ concepts to existing library components with great caution</h3>
<p><strong>Rationale:</strong> <a href="https://en.wikipedia.org/wiki/Here_be_dragons"><em>Here be dragons</em></a>. At the moment we simply do not know the extent of user code breakage that will be caused by applying C++ concepts as proposed by the <em>Ranges TS</em>. We do know that simply adding constraints via <em>requires-clause</em>s as replacements for now-traditional <code>enable-if</code> SFINAE is detectable, and that it has the potential to affect user code. (See <a href="https://wg21.link/p0552"><code>enable_if</code> vs. <code>requires</code>: A Case Study</a>.)</p>
<p>The best way to slay these dragons is to demonstrate that most do not exist, and that's the point of the <a href="#recommendation-solicit-ranges-ts-user-feedback">User feedback recommendation</a> above. Where real dragons are actually encountered, <a href="https://wg21.link/p0684">P0648 <em>C++ Stability, Velocity, and Deployment Plans</em></a> is our best hope for mitigation. But caution is called for in the meantime.</p>
<hr />
</body>
</html>
