<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 1321: scoped_allocator_adaptor construct and destroy don't
use allocator_traits</title>
<meta property="og:title" content="Issue 1321: scoped_allocator_adaptor construct and destroy don't
use allocator_traits">
<meta property="og:description" content="C++ library issue. Status: Resolved">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue1321.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#Resolved">Resolved</a> status.</em></p>
<h3 id="1321"><a href="lwg-defects.html#1321">1321</a>. <code>scoped_allocator_adaptor construct</code> and <code>destroy</code> don't
use <code>allocator_traits</code></h3>
<p><b>Section:</b> 20.6.4 <a href="https://wg21.link/allocator.adaptor.members">[allocator.adaptor.members]</a> <b>Status:</b> <a href="lwg-active.html#Resolved">Resolved</a>
 <b>Submitter:</b> Howard Hinnant <b>Opened:</b> 2010-02-16 <b>Last modified:</b> 2016-01-28</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View all other</b> <a href="lwg-index.html#allocator.adaptor.members">issues</a> in [allocator.adaptor.members].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#Resolved">Resolved</a> status.</p>
<p><b>Discussion:</b></p>
<p>
20.6.4 <a href="https://wg21.link/allocator.adaptor.members">[allocator.adaptor.members]</a> p8-9 says:
</p>

<blockquote>

<pre>
template &lt;class T, class... Args&gt;
  void construct(T* p, Args&amp;&amp;... args);
</pre>
<blockquote>
<p>
8 <i>Effects:</i> let <code><i>OUTERMOST</i>(x)</code> be <code>x</code> if <code>x</code>
does not have an <code>outer_allocator()</code> function and
<code><i>OUTERMOST</i>(x.outer_allocator())</code> otherwise.
</p>

<ul>
<li>
If <code>uses_allocator&lt;T, inner_allocator_type&gt;::value</code> is
<code>false</code> and <code>is_constructible&lt;T, Args...&gt;::value</code> is
<code>true</code>, calls <code><i>OUTERMOST</i>(*this).construct(p,
std::forward&lt;Args&gt;(args)...)</code>.
</li>

<li>
Otherwise, if <code>uses_allocator&lt;T, inner_allocator_type&gt;::value</code> is
<code>true</code> and <code>is_constructible&lt;T, allocator_arg_t,
inner_allocator_type, Args...&gt;::value</code> is <code>true</code>, calls
<code><i>OUTERMOST</i>(*this).construct(p, allocator_arg,
inner_allocator(),std::forward&lt;Args&gt;(args)...)</code>.
</li>

<li>
Otherwise, if <code>uses_allocator&lt;T, inner_allocator_type&gt;::value</code> is
<code>true</code> and <code>is_constructible&lt;T, Args...,
inner_allocator_type&gt;::value</code> is <code>true</code>, calls
<code><i>OUTERMOST</i>(*this).construct(p, std::forward&lt;Args&gt;(args)...,
inner_allocator())</code>.
</li>

<li>
Otherwise, the program is ill-formed. [<i>Note:</i> an error will result if
<code>uses_allocator</code> evaluates to <code>true</code> but the specific constructor
does not take an allocator. This definition prevents a silent failure to pass an
inner allocator to a contained element. &mdash; <i>end note</i>]
</li>
</ul>

</blockquote>

<pre>
template &lt;class T&gt;
  void destroy(T* p);
</pre>
<blockquote><p>
9 <i>Effects:</i> calls <code>outer_allocator().destroy(p)</code>.
</p></blockquote>

</blockquote>

<p>
In all other calls where applicable <code>scoped_allocator_adaptor</code> does not
call members of an allocator directly, but rather does so indirectly via
<code>allocator_traits</code>.  For example:
</p>

<blockquote>
<pre>
size_type max_size() const;
</pre>
<blockquote><p>
7 <i>Returns:</i>
<code><b>allocator_traits&lt;OuterAlloc&gt;::</b>max_size(outer_allocator())</code>.
</p></blockquote>
</blockquote>

<p>
Indeed, without the indirection through <code>allocator_traits</code> the
definitions for <code>construct</code> and <code>destroy</code> are likely to fail at
compile time since the <code>outer_allocator()</code> may not have the members
<code>construct</code> and <code>destroy</code>.
</p>

<p><i>[
The proposed wording is a product of Pablo, Daniel and Howard.
]</i></p>


<p><i>[
2010 Pittsburgh:  Moved to NAD Editorial.  Rationale added below.
]</i></p>




<p><b>Rationale:</b></p>
<p>
Solved by
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3059.pdf">N3059</a>.
</p>


<p id="res-1321"><b>Proposed resolution:</b></p>
<p>
In 20.6.4 <a href="https://wg21.link/allocator.adaptor.members">[allocator.adaptor.members]</a> move and change p8
as indicated, and change p9 as indicated:
</p>

<blockquote>

<p>
<ins>Let <code><i>OUTERMOST(x)</i></code> be <code><i>x</i></code> if <code><i>x</i></code>
does not have an <code>outer_allocator()</code> <ins>member</ins> function and
<code><i>OUTERMOST(x.outer_allocator())</i></code> otherwise. Let
<code><i>OUTERMOST_ALLOC_TRAITS(x)</i></code> be
<code>allocator_traits&lt;decltype(<i>OUTERMOST(x)</i>)&gt;</code>.
[<i>Note:</i> <code><i>OUTERMOST(x)</i></code> and
<code><i>OUTERMOST_ALLOC_TRAITS(x)</i></code> are recursive operations.  It is
incumbent upon the definition of <code>outer_allocator()</code> to ensure that the
recursion terminates.  It <em>will</em> terminate for all instantiations
of <code>scoped_allocator_adaptor</code>. &mdash; <i>end note</i>]
</ins>
</p>

<pre>
template &lt;class T, class... Args&gt;
  void construct(T* p, Args&amp;&amp;... args);
</pre>
<blockquote>

<p>
8 <i>Effects:</i> <del>let <code><i>OUTERMOST(x)</i></code> be <code><i>x</i></code> if
<code><i>x</i></code> does not have an <code>outer_allocator()</code> function and
<code><i>OUTERMOST(x.outer_allocator())</i></code> otherwise.</del>
</p>

<ul>
<li>
If <code>uses_allocator&lt;T, inner_allocator_type&gt;::value</code> is
<code>false</code> and <code>is_constructible&lt;T, Args...&gt;::value</code> is
<code>true</code>, calls <code><del><i>OUTERMOST(*this)</i>.</del>
<ins><i>OUTERMOST_ALLOC_TRAITS(outer_allocator())</i>::</ins>construct(
<ins><i>OUTERMOST(outer_allocator())</i>,</ins> p,
std::forward&lt;Args&gt;(args)... )</code>.
</li>

<li>
Otherwise, if <code>uses_allocator&lt;T, inner_allocator_type&gt;::value</code> is
<code>true</code> and <code>is_constructible&lt;T, allocator_arg_t,
inner_allocator_type, Args...&gt;::value</code> is <code>true</code>, calls
<code><del><i>OUTERMOST(*this)</i>.</del>
<ins><i>OUTERMOST_ALLOC_TRAITS(outer_allocator())</i>::</ins>construct(
<ins><i>OUTERMOST(outer_allocator())</i>,</ins> p, allocator_arg,
inner_allocator(), std::forward&lt;Args&gt;(args)... )</code>.
</li>

<li>
Otherwise, if <code>uses_allocator&lt;T, inner_allocator_type&gt;::value</code> is
<code>true</code> and <code>is_constructible&lt;T, Args...,
inner_allocator_type&gt;::value</code> is <code>true</code>, calls
<code><del><i>OUTERMOST(*this)</i>.</del>
<ins><i>OUTERMOST_ALLOC_TRAITS(outer_allocator())</i>::</ins>construct(
<ins><i>OUTERMOST(outer_allocator())</i>,</ins> p,
std::forward&lt;Args&gt;(args)..., inner_allocator() )</code>.
</li>

<li>
Otherwise, the program is ill-formed. [<i>Note:</i> an error will result if
<code>uses_allocator</code> evaluates to <code>true</code> but the specific constructor
does not take an allocator. This definition prevents a silent failure to pass an
inner allocator to a contained element. &mdash; <i>end note</i>]
</li>
</ul>

</blockquote>

<pre>
template &lt;class T&gt;
  void destroy(T* p);
</pre>
<blockquote><p>
9 <i>Effects:</i> calls <code><del>outer_allocator().</del>
<ins><i>OUTERMOST_ALLOC_TRAITS(outer_allocator())</i>::</ins>destroy(
<ins><i>OUTERMOST(outer_allocator())</i>,</ins> p)</code>.
</p></blockquote>

</blockquote>






</body>
</html>
