<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 1194: Unintended queue constructor</title>
<meta property="og:title" content="Issue 1194: Unintended queue constructor">
<meta property="og:description" content="C++ library issue. Status: C++11">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue1194.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++11">C++11</a> status.</em></p>
<h3 id="1194"><a href="lwg-defects.html#1194">1194</a>. Unintended <code>queue</code> constructor</h3>
<p><b>Section:</b> 23.6 <a href="https://wg21.link/container.adaptors">[container.adaptors]</a> <b>Status:</b> <a href="lwg-active.html#C++11">C++11</a>
 <b>Submitter:</b> Howard Hinnant <b>Opened:</b> 2009-08-20 <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#container.adaptors">issues</a> in [container.adaptors].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++11">C++11</a> status.</p>
<p><b>Discussion:</b></p>
<p>
23.6.3.1 <a href="https://wg21.link/queue.defn">[queue.defn]</a> has the following <code>queue</code> constructor:
</p>

<blockquote><pre>
template &lt;class Alloc&gt; explicit queue(const Alloc&amp;);
</pre></blockquote>

<p>
This will be implemented like so:
</p>

<blockquote><pre>
template &lt;class Alloc&gt; explicit queue(const Alloc&amp; a) : c(a) {}
</pre></blockquote>

<p>
The issue is that <code>Alloc</code> can be anything that a container will construct
from, for example an <code>int</code>.  Is this intended to compile?
</p>

<blockquote><pre>
queue&lt;int&gt; q(5);
</pre></blockquote>

<p>
Before the addition of this constructor, <code>queue&lt;int&gt;(5)</code> would not compile.
I ask, not because this crashes, but because it is new and appears to be
unintended.  We do not want to be in a position of accidently introducing this
"feature" in C++0X and later attempting to remove it.
</p>

<p>
I've picked on <code>queue</code>.  <code>priority_queue</code> and <code>stack</code> have
the same issue.  Is it useful to create a <code>priority_queue</code> of 5
identical elements?
</p>

<p><i>[
Daniel, Howard and Pablo collaborated on the proposed wording.
]</i></p>


<p><i>[
2009-10 Santa Cruz:
]</i></p>


<blockquote><p>
Move to Ready.
</p></blockquote>



<p id="res-1194"><b>Proposed resolution:</b></p>

<p><i>[
This resolution includes a semi-editorial clean up, giving definitions to members
which in some cases weren't defined since C++98.
This resolution also offers editorially different wording for <a href="lwg-defects.html#976" title="Class template std::stack should be movable (Status: Resolved)">976</a><sup><a href="https://cplusplus.github.io/LWG/issue976" title="Latest snapshot">(i)</a></sup>,
and it also provides wording for <a href="lwg-defects.html#1196" title="move semantics undefined for priority_queue (Status: Resolved)">1196</a><sup><a href="https://cplusplus.github.io/LWG/issue1196" title="Latest snapshot">(i)</a></sup>.
]</i></p>


<p>
Change  [ontainer.adaptor], p1:
</p>

<blockquote><p>
The container adaptors each take a <code>Container</code> template parameter, and
each constructor takes a <code>Container</code> reference argument. This container is
copied into the <code>Container</code> member of each adaptor. If the container takes
an allocator, then a compatible allocator may be passed in to the
adaptor's constructor. Otherwise, normal copy or move construction is
used for the container argument. <del>[<i>Note:</i> it is not necessary for an
implementation to distinguish between the one-argument constructor that
takes a <code>Container</code> and the one- argument constructor that takes an
allocator_type. Both forms use their argument to construct an instance
of the container. &mdash; <i>end note</i>]</del>
</p></blockquote>

<p>
Change  [ueue.def], p1:
</p>

<blockquote><pre>
template &lt;class T, class Container = deque&lt;T&gt; &gt;
class queue {
public:
  typedef typename Container::value_type      value_type;
  typedef typename Container::reference       reference;
  typedef typename Container::const_reference const_reference;
  typedef typename Container::size_type       size_type;
  typedef Container                           container_type;
protected:
  Container c;

public:
  explicit queue(const Container&amp;);
  explicit queue(Container&amp;&amp; = Container());
  queue(queue&amp;&amp; q)<ins>;</ins><del> : c(std::move(q.c)) {}</del>
  template &lt;class Alloc&gt; explicit queue(const Alloc&amp;);
  template &lt;class Alloc&gt; queue(const Container&amp;, const Alloc&amp;);
  template &lt;class Alloc&gt; queue(Container&amp;&amp;, const Alloc&amp;);
  template &lt;class Alloc&gt; queue(queue&amp;&amp;, const Alloc&amp;);
  queue&amp; operator=(queue&amp;&amp; q)<ins>;</ins><del> { c = std::move(q.c); return *this; }</del>

  bool empty() const          { return c.empty(); }
  ...
};
</pre></blockquote>

<p>
Add a new section after 23.6.3.1 <a href="https://wg21.link/queue.defn">[queue.defn]</a>, [queue.cons]:
</p>

<blockquote>
<p><b><code>queue</code> constructors [queue.cons]</b></p>

<pre>
explicit queue(const Container&amp; cont);
</pre>

<blockquote>

<p>
<i>Effects:</i> Initializes <code>c</code> with <code>cont</code>.
</p>

</blockquote>

<pre>
explicit queue(Container&amp;&amp; cont = Container());
</pre>

<blockquote>

<p>
<i>Effects:</i> Initializes <code>c</code> with <code>std::move(cont)</code>.
</p>

</blockquote>

<pre>
queue(queue&amp;&amp; q)
</pre>

<blockquote>

<p>
<i>Effects:</i> Initializes <code>c</code> with <code>std::move(q.c)</code>.
</p>

</blockquote>

<p>
For each of the following constructors,
if <code>uses_allocator&lt;container_type, Alloc&gt;::value</code> is <code>false</code>,
then the constructor shall not participate in overload resolution.
</p>

<pre>
template &lt;class Alloc&gt; 
  explicit queue(const Alloc&amp; a);
</pre>

<blockquote>

<p>
<i>Effects:</i> Initializes <code>c</code> with <code>a</code>.
</p>

</blockquote>

<pre>
template &lt;class Alloc&gt; 
  queue(const container_type&amp; cont, const Alloc&amp; a);
</pre>

<blockquote>

<p>
<i>Effects:</i> Initializes <code>c</code> with <code>cont</code> as the first
argument and <code>a</code> as the second argument.
</p>

</blockquote>

<pre>
template &lt;class Alloc&gt; 
  queue(container_type&amp;&amp; cont, const Alloc&amp; a);
</pre>

<blockquote>

<p>
<i>Effects:</i> Initializes <code>c</code> with <code>std::move(cont)</code> as the
first argument and <code>a</code> as the second argument.
</p>

</blockquote>

<pre>
template &lt;class Alloc&gt; 
  queue(queue&amp;&amp; q, const Alloc&amp; a);
</pre>

<blockquote>

<p>
<i>Effects:</i> Initializes <code>c</code> with <code>std::move(q.c)</code> as the
first argument and <code>a</code> as the second argument.
</p>

</blockquote>

<pre>
queue&amp; operator=(queue&amp;&amp; q);
</pre>

<blockquote>

<p>
<i>Effects:</i> Assigns <code>c</code> with <code>std::move(q.c)</code>.
</p>

<p>
<i>Returns:</i> <code>*this</code>.
</p>

</blockquote>



</blockquote>

<p>
Add to 23.6.4.2 <a href="https://wg21.link/priqueue.cons">[priqueue.cons]</a>:
</p>

<blockquote>

<pre>
priority_queue(priority_queue&amp;&amp; q);
</pre>

<blockquote>

<p>
<i>Effects:</i> Initializes <code>c</code> with <code>std::move(q.c)</code> and
initializes <code>comp</code> with <code>std::move(q.comp)</code>.
</p>

</blockquote>

<p>
For each of the following constructors,
if <code>uses_allocator&lt;container_type, Alloc&gt;::value</code> is <code>false</code>,
then the constructor shall not participate in overload resolution.
</p>

<pre>
template &lt;class Alloc&gt;
  explicit priority_queue(const Alloc&amp; a);
</pre>

<blockquote>

<p>
<i>Effects:</i> Initializes <code>c</code> with <code>a</code> and value-initializes <code>comp</code>.
</p>

</blockquote>

<pre>
template &lt;class Alloc&gt;
  priority_queue(const Compare&amp; compare, const Alloc&amp; a);
</pre>

<blockquote>

<p>
<i>Effects:</i> Initializes <code>c</code> with <code>a</code> and initializes <code>comp</code>
with <code>compare</code>.
</p>

</blockquote>

<pre>
template &lt;class Alloc&gt;
  priority_queue(const Compare&amp; compare, const Container&amp; cont, const Alloc&amp; a);
</pre>

<blockquote>

<p>
<i>Effects:</i> Initializes <code>c</code> with <code>cont</code> as the first argument
and <code>a</code> as the second argument,
and initializes <code>comp</code> with <code>compare</code>.
</p>

</blockquote>

<pre>
template &lt;class Alloc&gt;
  priority_queue(const Compare&amp; compare, Container&amp;&amp; cont, const Alloc&amp; a);
</pre>

<blockquote>

<p>
<i>Effects:</i> Initializes <code>c</code> with <code>std::move(cont)</code> as 
the first argument and <code>a</code> as the second argument,
and initializes <code>comp</code> with <code>compare</code>.
</p>

</blockquote>

<pre>
template &lt;class Alloc&gt;
  priority_queue(priority_queue&amp;&amp; q, const Alloc&amp; a);
</pre>

<blockquote>

<p>
<i>Effects:</i> Initializes <code>c</code> with <code>std::move(q.c)</code> as the
first argument and <code>a</code> as the second argument, 
and initializes <code>comp</code> with <code>std::move(q.comp)</code>.
</p>

</blockquote>

<pre>
priority_queue&amp; operator=(priority_queue&amp;&amp; q);
</pre>

<blockquote>

<p>
<i>Effects:</i> Assigns <code>c</code> with <code>std::move(q.c)</code> and
assigns <code>comp</code> with <code>std::move(q.comp)</code>.
</p>

<p>
<i>Returns:</i> <code>*this</code>.
</p>

</blockquote>

</blockquote>




<p>
Change 23.6.6.2 <a href="https://wg21.link/stack.defn">[stack.defn]</a>:
</p>

<blockquote><pre>
template &lt;class T, class Container = deque&lt;T&gt; &gt;
class stack {
public:
  typedef typename Container::value_type      value_type;
  typedef typename Container::reference       reference;
  typedef typename Container::const_reference const_reference;
  typedef typename Container::size_type       size_type;
  typedef Container                           container_type;
protected:
  Container c;

public:
  explicit stack(const Container&amp;);
  explicit stack(Container&amp;&amp; = Container());
  <ins>stack(stack&amp;&amp; s);</ins>
  template &lt;class Alloc&gt; explicit stack(const Alloc&amp;);
  template &lt;class Alloc&gt; stack(const Container&amp;, const Alloc&amp;);
  template &lt;class Alloc&gt; stack(Container&amp;&amp;, const Alloc&amp;);
  template &lt;class Alloc&gt; stack(stack&amp;&amp;, const Alloc&amp;);
  <ins>stack&amp; operator=(stack&amp;&amp; s);</ins>

  bool empty() const          { return c.empty(); }
  ...
};
</pre></blockquote>

<p>
Add a new section after 23.6.6.2 <a href="https://wg21.link/stack.defn">[stack.defn]</a>, [stack.cons]:
</p>

<blockquote>
<p><b><code>stack</code> constructors [stack.cons]</b></p>

<pre>
stack(stack&amp;&amp; s);
</pre>

<blockquote>

<p>
<i>Effects:</i> Initializes <code>c</code> with <code>std::move(s.c)</code>.
</p>

</blockquote>

<p>
For each of the following constructors,
if <code>uses_allocator&lt;container_type, Alloc&gt;::value</code> is <code>false</code>,
then the constructor shall not participate in overload resolution.
</p>

<pre>
template &lt;class Alloc&gt; 
  explicit stack(const Alloc&amp; a);
</pre>

<blockquote>

<p>
<i>Effects:</i> Initializes <code>c</code> with <code>a</code>.
</p>

</blockquote>

<pre>
template &lt;class Alloc&gt; 
  stack(const container_type&amp; cont, const Alloc&amp; a);
</pre>

<blockquote>

<p>
<i>Effects:</i> Initializes <code>c</code> with <code>cont</code> as the
first argument and <code>a</code> as the second argument.
</p>

</blockquote>

<pre>
template &lt;class Alloc&gt; 
  stack(container_type&amp;&amp; cont, const Alloc&amp; a);
</pre>

<blockquote>

<p>
<i>Effects:</i> Initializes <code>c</code> with <code>std::move(cont)</code> as the
first argument and <code>a</code> as the second argument.
</p>

</blockquote>

<pre>
template &lt;class Alloc&gt; 
  stack(stack&amp;&amp; s, const Alloc&amp; a);
</pre>

<blockquote>

<p>
<i>Effects:</i> Initializes <code>c</code> with <code>std::move(s.c)</code> as the
first argument and <code>a</code> as the second argument.
</p>

</blockquote>

<pre>
stack&amp; operator=(stack&amp;&amp; s);
</pre>

<blockquote>

<p>
<i>Effects:</i> Assigns <code>c</code> with <code>std::move(s.c)</code>.
</p>

<p>
<i>Returns:</i> <code>*this</code>.
</p>

</blockquote>

</blockquote>






</body>
</html>
