<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<style type="text/css">
pre {margin-left:20pt; }
pre > i   { font-family: "OCR A Extended", "Consolas", "Lucida Console", monospace;  font-style:italic; }
code > i  { font-family: "OCR A Extended", "Consolas", "Lucida Console", monospace;  font-style:italic; }
pre > em  { font-family: "OCR A Extended", "Consolas", "Lucida Console", monospace;  font-style:italic; }
code > em { font-family: "OCR A Extended", "Consolas", "Lucida Console", monospace;  font-style:italic; }
body { color: #000000; background-color: #FFFFFF; }
del { text-decoration: line-through; color: #8B0040; }
ins { text-decoration: underline; color: #005100; }

p.example   { margin-left: 2em; }
pre.example { margin-left: 2em; }
div.example { margin-left: 2em; }

code.extract { background-color: #F5F6A2; }
pre.extract  { margin-left: 2em; background-color: #F5F6A2;  border: 1px solid #E1E28E; }

p.function    { }
.attribute    { margin-left: 2em; }
.attribute dt { float: left; font-style: italic;  padding-right: 1ex; }
.attribute dd { margin-left: 0em; }

blockquote.std    { color: #000000; background-color: #F1F1F1;  border: 1px solid #D1D1D1;  padding-left: 0.5em; padding-right: 0.5em; }
blockquote.stddel { text-decoration: line-through;  color: #000000; background-color: #FFEBFF;  border: 1px solid #ECD7EC;  padding-left: 0.5empadding-right: 0.5em; ; }
blockquote.stdins { text-decoration: underline;  color: #000000; background-color: #C8FFC8;  border: 1px solid #B3EBB3; padding: 0.5em; }
table.header { border: 0px; border-spacing: 0;  margin-left: 0px; font-style: normal; }
table { border: 1px solid black; border-spacing: 0px;  margin-left: auto; margin-right: auto; }
th { text-align: left; vertical-align: top;  padding-left: 0.4em; border: none;  padding-right: 0.4em; border: none; }
td { text-align: left; vertical-align: top;  padding-left: 0.4em; border: none;  padding-right: 0.4em; border: none; }
</style>

<title>Rename `_default_init` functions and do nothing more</title>
</head>

<body>

<table class="header"><tbody>
  <tr>
    <th>Document number:&nbsp;&nbsp;</th><th> </th><td>P1978R0</td>
  </tr>
  <tr>
    <th>Authors:&nbsp;&nbsp;</th><th> </th><td>Andrzej Krzemieński <br>Glen Joseph Fernandes<br> Nevin Liber<br> Peter Dimov</td>
  </tr>
  <tr>
    <th>Date:&nbsp;&nbsp;</th><th> </th><td>2019-11-15</td>
  </tr>
  <tr>
    <th>Audience:&nbsp;&nbsp;</th><th> </th><td>Library Evolution Working Group</td>
  </tr>
  <tr>
    <th>Reply-to:&nbsp;&nbsp;</th><th> </th><td><address>Andrzej Krzemieński &lt;akrzemi1 at gmail dot com&gt;</address><address>Glen Joseph Fernandes &lt;glenjofe at gmail dot com&gt;</address></td>
  </tr>
</tbody></table>

<h1><a name="title">Rename <code>_default_init</code> functions and do nothing more</a></h1>

<h2><a name="intro">1. Introduction</a></h2>

<p>While addressing national body comment <a href="https://github.com/cplusplus/nbballot/issues/2">DE002</a>, LEWG came up with the solution
   that went beyond changing function names (as requested in DE002), but also changed the design of these functions by applying constrains
   which renders these functions very difficult to use in generic contexts. In this paper we propose a smaller solution that is more in line with
   DE002, and that does not attempt to do a last-minute redesign.</p>

<h2><a name="discussion">2. Discussion</a></h2>

<p>The problem reported in DE002 is that functions that are meant to perform default initialization of heap-allocated objects are spelled like
   <code>make_unique_default_init</code>, which may mislead non-expert programmers &mdash; who do not understand terms from the Standard like "default initialization" &mdash;
   to believe that objects will be initialized to their safe default values (which experst call "value initialization").</p>

<p>In response to that, <a href="http://wiki.edg.com/pub/Wg21belfast/LibraryEvolutionWorkingGroup/D1973R0_rename_default_init_funcs.pdf">P1973R0</a>
   changes the names to <code>make_unique_uninitilized</code>, which now confuses a different group of non-experts, by incorrectly implying that these objects
   are uninitialized. In order to avoid this new confusion, P1973R0 additionally proposes SFINAE-like constrains that make these functions available only
   for types that are trivially default-constructible, which only partially mitigates the new confusion, but also makes these functions very difficult to use inside
   templates.</p>
   
<p>Here is an example that now becomes difficult to write:</p>

<pre>template &lt;typename T, size_t Size&gt;
std::unique_ptr&lt;T[]&gt; initialize_array()
{
  auto result = std::make_unique_default_init&lt;T[]&gt;(Size);
  for (size_t i = 0; i != Size; ++i)
    result[i] = produce_value&lt;T&gt;(i);
	
  return result;
}</pre>

<p>We first need to allocate the array, and only then fill it with meaningful values, so the initial values are never read. We want to perform this initialization
   as fast as we can for every <code>T</code>. This means that for types with user-provided default constructor we have to call this constructor, but for trivial types
   we do the trivial initialization. With the solution proposed in P1973R0, writing this template is not that easy anymore. We have to either provide a specialisation
   or use an <code>if constexpr</code> to distinguish the two cases. The soluiton in P1973R0 seems to be missing the point of introducing these functions in the first place,
   and disregarding this idiomatic use. This, in turn, impedes the migration from <code>boost::make_unique_noinit</code>.</p>
   
<p>In the light of the above, we propose, as per DE002, to only change the names of these functions to <code>make_unique_minimal_init</code>, and refrain from any other design changes.
   Term "minimal" seems to be conveying the idea behind the idiom on the one hand, and on the other not to overlap with any expert term in the Standard, thus avoiding any confusion.</p>
   

<h2><a name="wording">3. Proposed wording</a></h2>

<p>Changes are relative to N4835.</p>

<p>Replace all occurrences of <code><del>make_unique_default_init</del></code> with <code><ins>make_unique_minimal_init</ins></code>.</p>

<p>Replace all occurrences of <code><del>make_shared_default_init</del></code> with <code><ins>make_shared_minimal_init</ins></code>.</p>

<p>Replace all occurrences of <code><del>allocate_shared_default_init</del></code> with <code><ins>allocate_shared_minimal_init</ins></code>.</p>
   


<h2><a name="literature">4. References</a></h2>

<ol>
  <li>[DE002],
      "Rename make_unique/shared_default_init to make_unique/shared_nonvalue_init",
	  (DE002, <a href="https://github.com/cplusplus/nbballot/issues/2">https://github.com/cplusplus/nbballot/issues/2</a>)</li>
		
  <li>[P1973r0], Nicolai Josuttis,
      "Rename '_default_init' Functions",
	  (P1973R0, <a href="http://wiki.edg.com/pub/Wg21belfast/LibraryEvolutionWorkingGroup/D1973R0_rename_default_init_funcs.pdf">http://wiki.edg.com/pub/Wg21belfast/LibraryEvolutionWorkingGroup/D1973R0_rename_default_init_funcs.pdf</a>)</li>
		 
</ol>

</body></html>
