<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2210: Missing allocator-extended constructor for allocator-aware containers</title>
<meta property="og:title" content="Issue 2210: Missing allocator-extended constructor for allocator-aware containers">
<meta property="og:description" content="C++ library issue. Status: C++14">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2210.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#C++14">C++14</a> status.</em></p>
<h3 id="2210"><a href="lwg-defects.html#2210">2210</a>. Missing allocator-extended constructor for allocator-aware containers</h3>
<p><b>Section:</b> 23.3 <a href="https://wg21.link/sequences">[sequences]</a>, 23.4 <a href="https://wg21.link/associative">[associative]</a>, 23.5 <a href="https://wg21.link/unord">[unord]</a> <b>Status:</b> <a href="lwg-active.html#C++14">C++14</a>
 <b>Submitter:</b> Jonathan Wakely <b>Opened:</b> 2012-11-01 <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#sequences">issues</a> in [sequences].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++14">C++14</a> status.</p>
<p><b>Discussion:</b></p>

<p>
The <code>forward_list(size_type)</code> constructor has no allocator-extended
equivalent, preventing the following code from compiling:
</p>
<blockquote><pre>
#include &lt;forward_list&gt;
#include &lt;vector&gt;
#include &lt;scoped_allocator&gt;

using namespace std;

int main()
{
  using list = forward_list&lt;int&gt;;
  vector&lt;list, scoped_allocator_adaptor&lt;list::allocator_type&gt;&gt; v;
  v.emplace_back(1u);
}
</pre></blockquote>
<p>
The very same problem exists for all allocator-aware sequence containers.
<p/>
In addition it exists for associative containers. For example, it's possible to construct 
<code>std::set&lt;int&gt;{0, 1, 2}</code> but not <code>std::set&lt;int&gt;{{0, 1, 2}, alloc}</code>, 
and possible to construct <code>std::set&lt;int&gt;{begin, end}</code> but not 
<code>std::set&lt;int&gt;{begin, end, alloc}</code>.
<p/>
This makes the following program fail when <code>SCOPED</code> is defined:
</p>
<blockquote><pre>
#include &lt;set&gt;
#include &lt;vector&gt;
#include &lt;scoped_allocator&gt;

#if SCOPED
using A = std::scoped_allocator_adaptor&lt;std::allocator&lt;int&gt;&gt;;
#else
using A = std::allocator&lt;int&gt;;
#endif

int main()
{
  int values[] = {0, 1, 2};
  std::vector&lt;std::set&lt;int&gt;, A&gt; v;
  v.emplace_back(std::begin(values), std::end(values));
}
</pre></blockquote>

<p><i>[2013-03-15 Issues Teleconference]</i></p>

<p>
Moved to Review.
</p>
<p>
Jonathan: There are lots of places where this is missing.
</p>
<p>
Howard: We should ping Pablo, this might be a deliberate design decision.
</p>

<p><i>[2013-04-18, Bristol]</i></p>




<p id="res-2210"><b>Proposed resolution:</b></p>
<p>This wording is relative to N3485.</p>

<ol>
<li><p>Edit the synopsis in 23.3.5.1 <a href="https://wg21.link/deque.overview">[deque.overview]</a>/2:</p>

<blockquote>
<pre>
namespace std {
  template &lt;class T, class Allocator = allocator&lt;T&gt; &gt;
  class deque {
  public:
    [&hellip;]
    explicit deque(const Allocator&amp; = Allocator());
    explicit deque(size_type n<ins>, const Allocator&amp; = Allocator()</ins>);
    [&hellip;]
  };
}
</pre>
</blockquote>
</li>

<li><p>Edit 23.3.5.2 <a href="https://wg21.link/deque.cons">[deque.cons]</a>/2:</p>

<blockquote>
<pre>
explicit deque(size_type n<ins>, const Allocator&amp; = Allocator()</ins>);
</pre>
<blockquote>
<p>
-3- <i>Effects</i>: Constructs a <code>deque</code> with <code>n</code> default-inserted elements
<ins>using the specified allocator</ins>.
</p>
</blockquote>
</blockquote>
</li>

<li><p>Edit the synopsis in  [forwardlist.overview]/3:</p>

<blockquote>
<pre>
namespace std {
  template &lt;class T, class Allocator = allocator&lt;T&gt; &gt;
  class forward_list {
  public:
    [&hellip;]
    explicit forward_list(const Allocator&amp; = Allocator());
    explicit forward_list(size_type n<ins>, const Allocator&amp; = Allocator()</ins>);
    [&hellip;]
  };
}
</pre>
</blockquote>
</li>

<li><p>Edit  [forwardlist.cons]/3:</p>

<blockquote>
<pre>
explicit forward_list(size_type n<ins>, const Allocator&amp; = Allocator()</ins>);
</pre>
<blockquote>
<p>
-3- <i>Effects</i>: Constructs a <code>forward_list</code> object with <code>n</code> default-inserted elements
<ins>using the specified allocator</ins>.
</p>
</blockquote>
</blockquote>
</li>

<li><p>Edit the synopsis in 23.3.11.1 <a href="https://wg21.link/list.overview">[list.overview]</a>/2:</p>

<blockquote>
<pre>
namespace std {
  template &lt;class T, class Allocator = allocator&lt;T&gt; &gt;
  class list {
  public:
    [&hellip;]
    explicit list(const Allocator&amp; = Allocator());
    explicit list(size_type n<ins>, const Allocator&amp; = Allocator()</ins>);
    [&hellip;]
  };
}
</pre>
</blockquote>
</li>

<li><p>Edit 23.3.11.2 <a href="https://wg21.link/list.cons">[list.cons]</a>/3:</p>

<blockquote>
<pre>
explicit list(size_type n<ins>, const Allocator&amp; = Allocator()</ins>);
</pre>
<blockquote>
<p>
-3- <i>Effects</i>: Constructs a <code>list</code> with <code>n</code> default-inserted elements
<ins>using the specified allocator</ins>.
</p>
</blockquote>
</blockquote>
</li>

<li><p>Edit the synopsis in 23.3.13.1 <a href="https://wg21.link/vector.overview">[vector.overview]</a>/2:</p>

<blockquote>
<pre>
namespace std {
  template &lt;class T, class Allocator = allocator&lt;T&gt; &gt;
  class vector {
  public:
    [&hellip;]
    explicit vector(const Allocator&amp; = Allocator());
    explicit vector(size_type n<ins>, const Allocator&amp; = Allocator()</ins>);
    [&hellip;]
  };
}
</pre>
</blockquote>
</li>

<li><p>Edit 23.3.13.2 <a href="https://wg21.link/vector.cons">[vector.cons]</a>/3:</p>

<blockquote>
<pre>
explicit vector(size_type n<ins>, const Allocator&amp; = Allocator()</ins>);
</pre>
<blockquote>
<p>
-3- <i>Effects</i>: Constructs a <code>vector</code> with <code>n</code> default-inserted elements
<ins>using the specified allocator</ins>.
</p>
</blockquote>
</blockquote>
</li>

<li><p>Edit the synopsis in 23.3.14 <a href="https://wg21.link/vector.bool">[vector.bool]</a>/1:</p>

<blockquote>
<pre>
namespace std {
  template &lt;class Allocator&gt; class vector&lt;bool, Allocator&gt; {
  class vector {
  public:
    [&hellip;]
    explicit vector(const Allocator&amp; = Allocator());
    <ins>explicit vector(size_type n, const Allocator&amp; = Allocator());</ins>
    <del>explicit</del> vector(size_type n, const bool&amp; value<del> = bool()</del>,
                    const Allocator&amp; = Allocator());
    [&hellip;]
  };
}
</pre>
</blockquote>
</li>

<li><p>Add to the synopsis in 23.4.3.1 <a href="https://wg21.link/map.overview">[map.overview]</a> p2:</p>

<blockquote>
<pre>
namespace std {
  template &lt;class Key, class T, class Compare = less&lt;Key&gt;,
    class Allocator = allocator&lt;pair&lt;const Key, T&gt; &gt; &gt; {
  class map {
  public:
    [&hellip;]
    map(initializer_list&lt;value_type&gt;,
      const Compare&amp; = Compare(),
      const Allocator&amp; = Allocator());
    <ins>template &lt;class InputIterator&gt;
    map(InputIterator first, InputIterator last, const Allocator&amp; a)
      : map(first, last, Compare(), a) { }
    map(initializer_list&lt;value_type&gt; il, const Allocator&amp; a)
      : map(il, Compare(), a) { }</ins>
    ~map();
    [&hellip;]
  };
}
</pre>
</blockquote>
</li>

<li><p>Add to the synopsis in 23.4.4.1 <a href="https://wg21.link/multimap.overview">[multimap.overview]</a> p2:</p>

<blockquote>
<pre>
namespace std {
  template &lt;class Key, class T, class Compare = less&lt;Key&gt;,
    class Allocator = allocator&lt;pair&lt;const Key, T&gt; &gt; &gt; {
  class multimap {
  public:
    [&hellip;]
    multimap(initializer_list&lt;value_type&gt;,
      const Compare&amp; = Compare(),
      const Allocator&amp; = Allocator());
    <ins>template &lt;class InputIterator&gt;
    multimap(InputIterator first, InputIterator last, const Allocator&amp; a)
      : multimap(first, last, Compare(), a) { }
    multimap(initializer_list&lt;value_type&gt; il, const Allocator&amp; a)
      : multimap(il, Compare(), a) { }</ins>
    ~multimap();
    [&hellip;]
  };
}
</pre>
</blockquote>
</li>

<li><p>Add to the synopsis in 23.4.6.1 <a href="https://wg21.link/set.overview">[set.overview]</a> p2:</p>

<blockquote>
<pre>
namespace std {
  template &lt;class Key, class Compare = less&lt;Key&gt;,
    class Allocator = allocator&lt;Key&gt; &gt; {
  class set {
  public:
    [&hellip;]
    set(initializer_list&lt;value_type&gt;,
      const Compare&amp; = Compare(),
      const Allocator&amp; = Allocator());
    <ins>template &lt;class InputIterator&gt;
    set(InputIterator first, InputIterator last, const Allocator&amp; a)
      : set(first, last, Compare(), a) { }
    set(initializer_list&lt;value_type&gt; il, const Allocator&amp; a)
      : set(il, Compare(), a) { }</ins>
    ~set();
    [&hellip;]
  };
}
</pre>
</blockquote>
</li>

<li><p>Add to the synopsis in 23.4.7.1 <a href="https://wg21.link/multiset.overview">[multiset.overview]</a> p2:</p>

<blockquote>
<pre>
namespace std {
  template &lt;class Key, class Compare = less&lt;Key&gt;,
    class Allocator = allocator&lt;Key&gt; &gt; {
  class multiset {
  public:
    [&hellip;]
    multiset(initializer_list&lt;value_type&gt;,
      const Compare&amp; = Compare(),
      const Allocator&amp; = Allocator());
    <ins>template &lt;class InputIterator&gt;
    multiset(InputIterator first, InputIterator last, const Allocator&amp; a)
      : multiset(first, last, Compare(), a) { }
    multiset(initializer_list&lt;value_type&gt; il, const Allocator&amp; a)
      : multiset(il, Compare(), a) { }</ins>
    ~multiset();
    [&hellip;]
  };
}
</pre>
</blockquote>
</li>

<li><p>Add to the synopsis in 23.5.3.1 <a href="https://wg21.link/unord.map.overview">[unord.map.overview]</a> p3:</p>

<blockquote>
<pre>
namespace std {
  template &lt;class Key, class T,
    class Hash = hash&lt;Key&gt;,
    class Pred = std::equal_to&lt;Key&gt;,
    class Allocator = std::allocator&lt;std::pair&lt;const Key, T&gt; &gt; &gt; {
  class unordered_map {
  public:
    [&hellip;]
    unordered_map(initializer_list&lt;value_type&gt;,
      size_type = <em>see below</em>,
      const hasher&amp; hf = hasher(),
      const key_equal&amp; eql = key_equal(),
      const allocator_type&amp; a = allocator_type());
    <ins>unordered_map(size_type n, const allocator_type&amp; a)
      : unordered_map(n, hasher(), key_equal(), a) { }
    unordered_map(size_type n, const hasher&amp; hf, const allocator_type&amp; a)
      : unordered_map(n, hf, key_equal(), a) { }
    template &lt;class InputIterator&gt;
      unordered_map(InputIterator f, InputIterator l, size_type n, const allocator_type&amp; a)
      : unordered_map(f, l, n, hasher(), key_equal(), a) { }
    template &lt;class InputIterator&gt;
      unordered_map(InputIterator f, InputIterator l, size_type n, const hasher&amp; hf, 
	    const allocator_type&amp; a)
      : unordered_map(f, l, n, hf, key_equal(), a) { }
    unordered_map(initializer_list&lt;value_type&gt; il, size_type n, const allocator_type&amp; a)
      : unordered_map(il, n, hasher(), key_equal(), a) { }
    unordered_map(initializer_list&lt;value_type&gt; il, size_type n, const hasher&amp; hf, 
	  const allocator_type&amp; a)
      : unordered_map(il, n, hf, key_equal(), a) { }</ins>
    ~unordered_map();
    [&hellip;]
  };
}
</pre>
</blockquote>
</li>

<li><p>Add to the synopsis in 23.5.4.1 <a href="https://wg21.link/unord.multimap.overview">[unord.multimap.overview]</a> p3:</p>

<blockquote>
<pre>
namespace std {
  template &lt;class Key, class T,
    class Hash = hash&lt;Key&gt;,
    class Pred = std::equal_to&lt;Key&gt;,
    class Allocator = std::allocator&lt;std::pair&lt;const Key, T&gt; &gt; &gt; {
  class unordered_multimap {
  public:
    [&hellip;]
    unordered_multimap(initializer_list&lt;value_type&gt;,
      size_type = <em>see below</em>,
      const hasher&amp; hf = hasher(),
      const key_equal&amp; eql = key_equal(),
      const allocator_type&amp; a = allocator_type());
    <ins>unordered_multimap(size_type n, const allocator_type&amp; a)
      : unordered_multimap(n, hasher(), key_equal(), a) { }
    unordered_multimap(size_type n, const hasher&amp; hf, const allocator_type&amp; a)
      : unordered_multimap(n, hf, key_equal(), a) { }
    template &lt;class InputIterator&gt;
      unordered_multimap(InputIterator f, InputIterator l, size_type n, const allocator_type&amp; a)
      : unordered_multimap(f, l, n, hasher(), key_equal(), a) { }
    template &lt;class InputIterator&gt;
      unordered_multimap(InputIterator f, InputIterator l, size_type n, const hasher&amp; hf, 
	    const allocator_type&amp; a)
      : unordered_multimap(f, l, n, hf, key_equal(), a) { }
    unordered_multimap(initializer_list&lt;value_type&gt; il, size_type n, const allocator_type&amp; a)
      : unordered_multimap(il, n, hasher(), key_equal(), a) { }
    unordered_multimap(initializer_list&lt;value_type&gt; il, size_type n, const hasher&amp; hf, 
	  const allocator_type&amp; a)
      : unordered_multimap(il, n, hf, key_equal(), a) { }</ins>
    ~unordered_multimap();
    [&hellip;]
  };
}
</pre>
</blockquote>
</li>

<li><p>Add to the synopsis in 23.5.6.1 <a href="https://wg21.link/unord.set.overview">[unord.set.overview]</a> p3:</p>

<blockquote>
<pre>
namespace std {
  template &lt;class Key,
    class Hash = hash&lt;Key&gt;,
    class Pred = std::equal_to&lt;Key&gt;,
    class Allocator = std::allocator&lt;Key&gt; &gt; {
  class unordered_set {
  public:
    [&hellip;]
    unordered_set(initializer_list&lt;value_type&gt;,
      size_type = <em>see below</em>,
      const hasher&amp; hf = hasher(),
      const key_equal&amp; eql = key_equal(),
      const allocator_type&amp; a = allocator_type());
    <ins>unordered_set(size_type n, const allocator_type&amp; a)
      : unordered_set(n, hasher(), key_equal(), a) { }
    unordered_set(size_type n, const hasher&amp; hf, const allocator_type&amp; a)
      : unordered_set(n, hf, key_equal(), a) { }
    template &lt;class InputIterator&gt;
      unordered_set(InputIterator f, InputIterator l, size_type n, const allocator_type&amp; a)
      : unordered_set(f, l, n, hasher(), key_equal(), a) { }
    template &lt;class InputIterator&gt;
      unordered_set(InputIterator f, InputIterator l, size_type n, const hasher&amp; hf, 
	    const allocator_type&amp; a)
      : unordered_set(f, l, n, hf, key_equal(), a) { }
    unordered_set(initializer_list&lt;value_type&gt; il, size_type n, const allocator_type&amp; a)
      : unordered_set(il, n, hasher(), key_equal(), a) { }
    unordered_set(initializer_list&lt;value_type&gt; il, size_type n, const hasher&amp; hf, 
	  const allocator_type&amp; a)
      : unordered_set(il, n, hf, key_equal(), a) { }</ins>
    ~unordered_set();
    [&hellip;]
  };
}
</pre>
</blockquote>
</li>

<li><p>Add to the synopsis in 23.5.7.1 <a href="https://wg21.link/unord.multiset.overview">[unord.multiset.overview]</a> p3:</p>

<blockquote>
<pre>
namespace std {
  template &lt;class Key,
    class Hash = hash&lt;Key&gt;,
    class Pred = std::equal_to&lt;Key&gt;,
    class Allocator = std::allocator&lt;Key&gt; &gt; {
  class unordered_multiset {
  public:
    [&hellip;]
    unordered_multiset(initializer_list&lt;value_type&gt;,
      size_type = <em>see below</em>,
      const hasher&amp; hf = hasher(),
      const key_equal&amp; eql = key_equal(),
      const allocator_type&amp; a = allocator_type());
    <ins>unordered_multiset(size_type n, const allocator_type&amp; a)
      : unordered_multiset(n, hasher(), key_equal(), a) { }
    unordered_multiset(size_type n, const hasher&amp; hf, const allocator_type&amp; a)
      : unordered_multiset(n, hf, key_equal(), a) { }
    template &lt;class InputIterator&gt;
      unordered_multiset(InputIterator f, InputIterator l, size_type n, const allocator_type&amp; a)
      : unordered_multiset(f, l, n, hasher(), key_equal(), a) { }
    template &lt;class InputIterator&gt;
      unordered_multiset(InputIterator f, InputIterator l, size_type n, const hasher&amp; hf, 
	    const allocator_type&amp; a)
      : unordered_multiset(f, l, n, hf, key_equal(), a) { }
    unordered_multiset(initializer_list&lt;value_type&gt; il, size_type n, const allocator_type&amp; a)
      : unordered_multiset(il, n, hasher(), key_equal(), a) { }
    unordered_multiset(initializer_list&lt;value_type&gt; il, size_type n, const hasher&amp; hf, 
	  const allocator_type&amp; a)
      : unordered_multiset(il, n, hf, key_equal(), a) { }</ins>
    ~unordered_multiset();
    [&hellip;]
  };
}
</pre>
</blockquote>
</li>
</ol>






</body>
</html>
