<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3884: flat_foo is missing allocator-extended copy/move constructors</title>
<meta property="og:title" content="Issue 3884: flat_foo is missing allocator-extended copy/move constructors">
<meta property="og:description" content="C++ library issue. Status: WP">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3884.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#WP">WP</a> status.</em></p>
<h3 id="3884"><a href="lwg-defects.html#3884">3884</a>. <code>flat_<i>foo</i></code> is missing allocator-extended copy/move constructors</h3>
<p><b>Section:</b> 23.6.8 <a href="https://wg21.link/flat.map">[flat.map]</a>, 23.6.9 <a href="https://wg21.link/flat.multimap">[flat.multimap]</a>, 23.6.11 <a href="https://wg21.link/flat.set">[flat.set]</a>, 23.6.12 <a href="https://wg21.link/flat.multiset">[flat.multiset]</a> <b>Status:</b> <a href="lwg-active.html#WP">WP</a>
 <b>Submitter:</b> Arthur O'Dwyer <b>Opened:</b> 2023-02-06 <b>Last modified:</b> 2023-11-22</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View other</b> <a href="lwg-index-open.html#flat.map">active issues</a> in [flat.map].</p>
<p><b>View all other</b> <a href="lwg-index.html#flat.map">issues</a> in [flat.map].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#WP">WP</a> status.</p>
<p><b>Discussion:</b></p>
<p>
This issue is part of the "<code>flat_<i>foo</i></code>" sequence, LWG <a href="lwg-defects.html#3786" title="Flat maps' deduction guide needs to default Allocator to be useful (Status: C++23)">3786</a><sup><a href="https://cplusplus.github.io/LWG/issue3786" title="Latest snapshot">(i)</a></sup>, <a href="lwg-active.html#3802" title="flat_foo allocator-extended constructors lack move semantics (Status: New)">3802</a><sup><a href="https://cplusplus.github.io/LWG/issue3802" title="Latest snapshot">(i)</a></sup>,
<a href="lwg-defects.html#3803" title="flat_foo constructors taking KeyContainer lack KeyCompare parameter (Status: C++23)">3803</a><sup><a href="https://cplusplus.github.io/LWG/issue3803" title="Latest snapshot">(i)</a></sup>, <a href="lwg-active.html#3804" title="flat_foo missing some allocator-extended deduction guides (Status: New)">3804</a><sup><a href="https://cplusplus.github.io/LWG/issue3804" title="Latest snapshot">(i)</a></sup>. <code>flat_set</code>, <code>flat_multiset</code>, <code>flat_map</code>, and
<code>flat_multimap</code> all have implicitly defaulted copy and move constructors, but they lack
allocator-extended versions of those constructors. This means that the following code is broken:
</p>
<blockquote><pre>
// <a href="https://godbolt.org/z/qezv5rTrW">https://godbolt.org/z/qezv5rTrW</a>
#include &lt;cassert&gt;
#include &lt;flat_set&gt;
#include &lt;memory_resource&gt;
#include &lt;utility&gt;
#include &lt;vector&gt;

template&lt;class T, class Comp = std::less&lt;T&gt;&gt;
using pmr_flat_set = std::flat_set&lt;T, Comp, std::pmr::vector&lt;T&gt;&gt;;

int main() {
  std::pmr::vector&lt;pmr_flat_set&lt;int&gt;&gt; vs = {
    {1,2,3},
    {4,5,6},
  };
  std::pmr::vector&lt;int&gt; v = std::move(vs[0]).extract();
  assert(v.get_allocator().resource() == std::pmr::get_default_resource());
}
</pre></blockquote>
<p>
<code>pmr_flat_set&lt;int&gt;</code> advertises that it "<code>uses_allocator</code>" <code>std::pmr::polymorphic_allocator&lt;int&gt;</code>,
but in fact it lacks the allocator-extended constructor overload set necessary to interoperate with <code>std::pmr::vector</code>.
</p>

<p><i>[2023-03-22; Reflector poll]</i></p>

<p>
Set status to Tentatively Ready after five votes in favour during reflector poll.
</p>

<p><i>[2023-06-17 Approved at June 2023 meeting in Varna. Status changed: Voting &rarr; WP.]</i></p>



<p id="res-3884"><b>Proposed resolution:</b></p>
<p>
This wording is relative to <a href="https://wg21.link/N4928" title=" Working Draft, Standard for Programming Language C++">N4928</a>.
</p>

<ol>
<li><p>Modify 23.6.8.2 <a href="https://wg21.link/flat.map.defn">[flat.map.defn]</a> as indicated:</p>

<blockquote>
<pre>
namespace std {
  template&lt;class Key, class T, class Compare = less&lt;Key&gt;,
  class KeyContainer = vector&lt;Key&gt;, class MappedContainer = vector&lt;T&gt;&gt;
  class flat_map {
  public:
    [&hellip;]
    // <i>23.6.8.3 <a href="https://wg21.link/flat.map.cons">[flat.map.cons]</a>, construct/copy/destroy</i>
    flat_map() : flat_map(key_compare()) { }

    <ins>template&lt;class Allocator&gt;
      flat_map(const flat_map&amp;, const Allocator&amp; a);
    template&lt;class Allocator&gt;
      flat_map(flat_map&amp;&amp;, const Allocator&amp; a);</ins>

    [&hellip;]
  };
  [&hellip;]
}
</pre>
</blockquote>

</li>

<li><p>Modify 23.6.8.3 <a href="https://wg21.link/flat.map.cons">[flat.map.cons]</a> as indicated:</p>

<blockquote class="note">
<p>
[<i>Drafting note</i>: As a drive-by fix, a missing closing <code>&gt;</code> is inserted in p11.]
</p>
</blockquote>

<blockquote>
<pre>
<ins>template&lt;class Allocator&gt;
  flat_map(const flat_map&amp;, const Allocator&amp; a);
template&lt;class Allocator&gt;
  flat_map(flat_map&amp;&amp;, const Allocator&amp; a);</ins>
template&lt;class Allocator&gt;
  flat_map(const key_compare&amp; comp, const Allocator&amp; a);
template&lt;class Allocator&gt;
  explicit flat_map(const Allocator&amp; a);
template&lt;class InputIterator, class Allocator&gt;
  flat_map(InputIterator first, InputIterator last, const key_compare&amp; comp, const Allocator&amp; a);
template&lt;class InputIterator, class Allocator&gt;
  flat_map(InputIterator first, InputIterator last, const Allocator&amp; a);
[&hellip;]
</pre>
<blockquote>
<p>
-11- <i>Constraints</i>: <code>uses_allocator_v&lt;key_container_type, Allocator<ins>&gt;</ins></code> is <code>true</code> and
<code>uses_allocator_v&lt;mapped_container_type, Allocator&gt;</code> is <code>true</code>.
<p/>
-12- <i>Effects</i>: Equivalent to the corresponding non-allocator constructors except that <code>c.keys</code> and
<code>c.values</code> are constructed with uses-allocator construction (20.2.8.2 <a href="https://wg21.link/allocator.uses.construction">[allocator.uses.construction]</a>).
</p>
</blockquote>
</blockquote>

</li>

<li><p>Modify 23.6.9.2 <a href="https://wg21.link/flat.multimap.defn">[flat.multimap.defn]</a> as indicated:</p>

<blockquote>
<pre>
namespace std {
  template&lt;class Key, class T, class Compare = less&lt;Key&gt;,
  class KeyContainer = vector&lt;Key&gt;, class MappedContainer = vector&lt;T&gt;&gt;
  class flat_multimap {
  public:
    [&hellip;]
    // <i>23.6.9.3 <a href="https://wg21.link/flat.multimap.cons">[flat.multimap.cons]</a>, construct/copy/destroy</i>
    flat_multimap() : flat_multimap(key_compare()) { }

    <ins>template&lt;class Allocator&gt;
      flat_multimap(const flat_multimap&amp;, const Allocator&amp; a);
    template&lt;class Allocator&gt;
      flat_multimap(flat_multimap&amp;&amp;, const Allocator&amp; a);</ins>

    [&hellip;]
  };
  [&hellip;]
}
</pre>
</blockquote>

</li>

<li><p>Modify 23.6.9.3 <a href="https://wg21.link/flat.multimap.cons">[flat.multimap.cons]</a> as indicated:</p>

<blockquote>
<pre>
<ins>template&lt;class Allocator&gt;
  flat_multimap(const flat_multimap&amp;, const Allocator&amp; a);
template&lt;class Allocator&gt;
  flat_multimap(flat_multimap&amp;&amp;, const Allocator&amp; a);</ins>
template&lt;class Allocator&gt;
  flat_multimap(const key_compare&amp; comp, const Allocator&amp; a);
[&hellip;]
</pre>
<blockquote>
<p>
-11- <i>Constraints</i>: <code>uses_allocator_v&lt;key_container_type, Allocator&gt;</code> is <code>true</code> and
<code>uses_allocator_v&lt;mapped_container_type, Allocator&gt;</code> is <code>true</code>.
<p/>
-12- <i>Effects</i>: Equivalent to the corresponding non-allocator constructors except that <code>c.keys</code> and
<code>c.values</code> are constructed with uses-allocator construction (20.2.8.2 <a href="https://wg21.link/allocator.uses.construction">[allocator.uses.construction]</a>).
</p>
</blockquote>
</blockquote>

</li>

<li><p>Modify 23.6.11.2 <a href="https://wg21.link/flat.set.defn">[flat.set.defn]</a> as indicated:</p>

<blockquote>
<pre>
namespace std {
  template&lt;class Key, class Compare = less&lt;Key&gt;, class KeyContainer = vector&lt;Key&gt;&gt;
  class flat_set {
  public:
    [&hellip;]
    // <i>23.6.11.3 <a href="https://wg21.link/flat.set.cons">[flat.set.cons]</a>, constructors</i>
    flat_set() : flat_set(key_compare()) { }

    <ins>template&lt;class Allocator&gt;
      flat_set(const flat_set&amp;, const Allocator&amp; a);
    template&lt;class Allocator&gt;
      flat_set(flat_set&amp;&amp;, const Allocator&amp; a);</ins>

    [&hellip;]
  };
  [&hellip;]
}
</pre>
</blockquote>

</li>

<li><p>Modify 23.6.11.3 <a href="https://wg21.link/flat.set.cons">[flat.set.cons]</a> as indicated:</p>

<blockquote>
<pre>
<ins>template&lt;class Allocator&gt;
  flat_set(const flat_set&amp;, const Allocator&amp; a);
template&lt;class Allocator&gt;
  flat_set(flat_set&amp;&amp;, const Allocator&amp; a);</ins>
template&lt;class Allocator&gt;
  flat_set(const key_compare&amp; comp, const Allocator&amp; a);
[&hellip;]
</pre>
<blockquote>
<p>
-9- <i>Constraints</i>: <code>uses_allocator_v&lt;container_type, Allocator&gt;</code> is <code>true</code>.
<p/>
-10- <i>Effects</i>: Equivalent to the corresponding non-allocator constructors except that <code><i>c</i></code> is
constructed with uses-allocator construction (20.2.8.2 <a href="https://wg21.link/allocator.uses.construction">[allocator.uses.construction]</a>).
</p>
</blockquote>
</blockquote>

</li>

<li><p>Modify 23.6.12.2 <a href="https://wg21.link/flat.multiset.defn">[flat.multiset.defn]</a> as indicated:</p>

<blockquote>
<pre>
namespace std {
  template&lt;class Key, class Compare = less&lt;Key&gt;, class KeyContainer = vector&lt;Key&gt;&gt;
  class flat_multiset {
  public:
    [&hellip;]
    // <i>23.6.12.3 <a href="https://wg21.link/flat.multiset.cons">[flat.multiset.cons]</a>, constructors</i>
    flat_multiset() : flat_multiset(key_compare()) { }

    <ins>template&lt;class Allocator&gt;
      flat_multiset(const flat_multiset&amp;, const Allocator&amp; a);
    template&lt;class Allocator&gt;
      flat_multiset(flat_multiset&amp;&amp;, const Allocator&amp; a);</ins>

    [&hellip;]
  };
  [&hellip;]
}
</pre>
</blockquote>

</li>

<li><p>Modify 23.6.12.3 <a href="https://wg21.link/flat.multiset.cons">[flat.multiset.cons]</a> as indicated:</p>

<blockquote>
<pre>
<ins>template&lt;class Allocator&gt;
  flat_multiset(const flat_multiset&amp;, const Allocator&amp; a);
template&lt;class Allocator&gt;
  flat_multiset(flat_multiset&amp;&amp;, const Allocator&amp; a);</ins>
template&lt;class Allocator&gt;
  flat_multiset(const key_compare&amp; comp, const Allocator&amp; a);
[&hellip;]
</pre>
<blockquote>
<p>
-9- <i>Constraints</i>: <code>uses_allocator_v&lt;container_type, Allocator&gt;</code> is <code>true</code>.
<p/>
-10- <i>Effects</i>: Equivalent to the corresponding non-allocator constructors except that <code><i>c</i></code> is
constructed with uses-allocator construction (20.2.8.2 <a href="https://wg21.link/allocator.uses.construction">[allocator.uses.construction]</a>).
</p>
</blockquote>
</blockquote>

</li>

</ol>





</body>
</html>
