<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3821: uses_allocator_construction_args should have overload for pair-like</title>
<meta property="og:title" content="Issue 3821: uses_allocator_construction_args should have overload for pair-like">
<meta property="og:description" content="C++ library issue. Status: C++23">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3821.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++23">C++23</a> status.</em></p>
<h3 id="3821"><a href="lwg-defects.html#3821">3821</a>. <code>uses_allocator_construction_args</code> should have overload for <i><code>pair-like</code></i></h3>
<p><b>Section:</b> 20.2.8.2 <a href="https://wg21.link/allocator.uses.construction">[allocator.uses.construction]</a> <b>Status:</b> <a href="lwg-active.html#C++23">C++23</a>
 <b>Submitter:</b> Tim Song <b>Opened:</b> 2022-11-08 <b>Last modified:</b> 2023-11-22</p>
<p><b>Priority: </b>2
</p>
<p><b>View other</b> <a href="lwg-index-open.html#allocator.uses.construction">active issues</a> in [allocator.uses.construction].</p>
<p><b>View all other</b> <a href="lwg-index.html#allocator.uses.construction">issues</a> in [allocator.uses.construction].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++23">C++23</a> status.</p>
<p><b>Discussion:</b></p>
<p>
<a href="https://wg21.link/P2165R4" title=" Compatibility between tuple, pair and tuple-like objects">P2165R4</a> added a <code><i>pair-like</i></code> constructor to 
<code>std::pair</code> but didn't add a corresponding <code>uses_allocator_construction_args</code> overload. 
It was in <a href="https://wg21.link/P2165R3" title=" Compatibility between tuple, pair and tuple-like objects">P2165R3</a> but incorrectly removed during the small group review.
<p/>
Without LWG <a href="lwg-defects.html#3525" title="uses_allocator_construction_args fails to handle types convertible to pair (Status: C++23)">3525</a><sup><a href="https://cplusplus.github.io/LWG/issue3525" title="Latest snapshot">(i)</a></sup>, not having the overload would have caused emplacing a <code><i>pair-like</i></code> into a 
<code>pmr::vector&lt;pair&gt;</code> to be outright ill-formed. 
<p/>
With that issue's resolution, in cases where the constructor is not explicit we would create a temporary pair 
and then do uses-allocator construction using its pieces, and it still won't work when the constructor is explicit.
<p/>
We should just do this properly.
</p>

<p><i>[2022-11-09 Tim updates wording following LWG review]</i></p>

<p>
During review of this issue LWG noticed that neither the constructor nor the new overload should accept <code>subrange</code>.
<p/>
The <code>remove_cv_t</code> in the new paragraph is added for consistency with LWG <a href="lwg-defects.html#3677" title="Is a cv-qualified pair specially handled in uses-allocator construction? (Status: C++23)">3677</a><sup><a href="https://cplusplus.github.io/LWG/issue3677" title="Latest snapshot">(i)</a></sup>.
</p> 

<p><i>[Kona 2022-11-12; Set priority to 2]</i></p>



<p><i>[2023-01-11; LWG telecon]</i></p>

<p>
Replace <code>P</code> with <code>U</code> in p17 and
set status to Tentatively Ready (poll result: 8/0/0).
</p>

<p><i>[2023-02-13 Approved at February 2023 meeting in Issaquah. Status changed: Voting &rarr; WP.]</i></p>



<p id="res-3821"><b>Proposed resolution:</b></p>
<p>
This wording is relative to <a href="https://wg21.link/N4917" title=" Working Draft, Standard for Programming Language C++">N4917</a> after the application of LWG <a href="lwg-defects.html#3677" title="Is a cv-qualified pair specially handled in uses-allocator construction? (Status: C++23)">3677</a><sup><a href="https://cplusplus.github.io/LWG/issue3677" title="Latest snapshot">(i)</a></sup>.
</p>
<ol>
<li><p>Edit 22.3.2 <a href="https://wg21.link/pairs.pair">[pairs.pair]</a> as indicated:</p>
<blockquote>
<pre>
template&lt;class U1, class U2&gt; constexpr explicit(<i>see below</i>) pair(pair&lt;U1, U2&gt;&amp; p);
template&lt;class U1, class U2&gt; constexpr explicit(<i>see below</i>) pair(const pair&lt;U1, U2&gt;&amp; p);
template&lt;class U1, class U2&gt; constexpr explicit(<i>see below</i>) pair(pair&lt;U1, U2&gt;&amp;&amp; p);
template&lt;class U1, class U2&gt; constexpr explicit(<i>see below</i>) pair(const pair&lt;U1, U2&gt;&amp;&amp; p);
template&lt;<i>pair-like</i> P&gt; constexpr explicit(<i>see below</i>) pair(P&amp;&amp; p);
</pre>
<blockquote>
<p>
-14- Let <code><i>FWD</i>(u)</code> be <code>static_cast&lt;decltype(u)&gt;(u)</code>.
<p/>
-15- <i>Constraints:</i>
</p>
<ol style="list-style-type: none">
<li><p><ins>(15.?) &mdash; For the last overload, <code>remove_cvref_t&lt;P&gt;</code> is not a specialization of <code>ranges::subrange</code>,</ins></p></li>
<li><p>(15.1) &mdash; <code>is_constructible_v&lt;T1, decltype(get&lt;0&gt;(<i>FWD</i>(p)))&gt;</code> is <code>true</code> and</p></li>
<li><p>(15.2) &mdash; <code>is_constructible_v&lt;T2, decltype(get&lt;1&gt;(<i>FWD</i>(p)))&gt;</code> is <code>true</code>.</p></li>
</ol>
<p>
-16- <i>Effects:</i> Initializes <code>first</code> with <code>get&lt;0&gt;(<i>FWD</i>(p))</code> 
and <code>second</code> with <code>get&lt;1&gt;(<i>FWD</i>(p))</code>.
</p>
</blockquote>
</blockquote>
</li>
<li><p>Edit 20.2.2 <a href="https://wg21.link/memory.syn">[memory.syn]</a>, header <code>&lt;memory&gt;</code> synopsis, as indicated:</p>
<blockquote>
<pre>
namespace std {
  [&hellip;]
  <i>// 20.2.8.2 <a href="https://wg21.link/allocator.uses.construction">[allocator.uses.construction]</a>, uses-allocator construction</i>
  [&hellip;]
  template&lt;class T, class Alloc, class U, class V&gt;
    constexpr auto uses_allocator_construction_args(const Alloc&amp; alloc,
                                                    pair&lt;U, V&gt;&amp; pr) noexcept;

  template&lt;class T, class Alloc, class U, class V&gt;
    constexpr auto uses_allocator_construction_args(const Alloc&amp; alloc,
                                                    const pair&lt;U, V&gt;&amp; pr) noexcept;

  template&lt;class T, class Alloc, class U, class V&gt;
    constexpr auto uses_allocator_construction_args(const Alloc&amp; alloc,
                                                    pair&lt;U, V&gt;&amp;&amp; pr) noexcept;

  template&lt;class T, class Alloc, class U, class V&gt;
    constexpr auto uses_allocator_construction_args(const Alloc&amp; alloc,
                                                    const pair&lt;U, V&gt;&amp;&amp; pr) noexcept;
<ins>  template&lt;class T, class Alloc, <i>pair-like</i> P&gt;
    constexpr auto uses_allocator_construction_args(const Alloc&amp; alloc, P&amp;&amp; p) noexcept;</ins>
    
  template&lt;class T, class Alloc, class U&gt;
    constexpr auto uses_allocator_construction_args(const Alloc&amp; alloc, U&amp;&amp; u) noexcept;
  [&hellip;]
}
</pre>
</blockquote>
</li>

<li><p>Add the following to 20.2.8.2 <a href="https://wg21.link/allocator.uses.construction">[allocator.uses.construction]</a>:</p>
<blockquote>
<pre>
<ins>  template&lt;class T, class Alloc, <i>pair-like</i> P&gt;
    constexpr auto uses_allocator_construction_args(const Alloc&amp; alloc, P&amp;&amp; p) noexcept;</ins>
</pre>
<blockquote>
<p>
<ins>-?- <i>Constraints:</i> <code>remove_cv_t&lt;T&gt;</code> is a specialization of <code>pair</code> 
and <code>remove_cvref_t&lt;P&gt;</code> is not a specialization of <code>ranges::subrange</code>.</ins>
<p/>
<ins>-?- <i>Effects:</i> Equivalent to:</ins>
</p>
<blockquote><pre><ins>
return uses_allocator_construction_args&lt;T&gt;(alloc, piecewise_construct,
                                            forward_as_tuple(get&lt;0&gt;(std::forward&lt;P&gt;(p))),
                                            forward_as_tuple(get&lt;1&gt;(std::forward&lt;P&gt;(p))));
</ins></pre></blockquote>
</blockquote>
</blockquote>
</li>

<li><p>Edit 20.2.8.2 <a href="https://wg21.link/allocator.uses.construction">[allocator.uses.construction]</a> p17:</p>
<blockquote>
<pre>
  template&lt;class T, class Alloc, class U&gt;
    constexpr auto uses_allocator_construction_args(const Alloc&amp; alloc, U&amp;&amp; u) noexcept;
</pre>
<blockquote>
<p>
-16- Let <code><i>FUN</i></code> be the function template:
</p>
<blockquote><pre>
  template&lt;class A, class B&gt;
  void <i>FUN</i>(const pair&lt;A, B&gt;&amp;);
</pre></blockquote>
<p>
-17- <i>Constraints:</i> <code>remove_cv_t&lt;T&gt;</code> is a specialization of <code>pair</code>, <ins>and either:</ins>
</p>
<ol style="list-style-type: none">
<li><p><ins>(17.1) &mdash; <code>remove_cvref_t&lt;U&gt;</code> is a specialization of <code>ranges::subrange</code>, or</ins></p></li>
<li><p><ins>(17.2) &mdash; <code>U</code> does not satisfy <i><code>pair-like</code></i></ins>
and the expression <code><i>FUN</i>(u)</code> is not well-formed when considered as an unevaluated operand..</p></li>
</ol>
</blockquote>
</blockquote>
</li>
</ol>





</body>
</html>
