<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 1048: Provide empty-state inspection for std::unique_future</title>
<meta property="og:title" content="Issue 1048: Provide empty-state inspection for std::unique_future">
<meta property="og:description" content="C++ library issue. Status: Resolved">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue1048.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="1048"><a href="lwg-defects.html#1048">1048</a>. Provide empty-state inspection for <code>std::unique_future</code></h3>
<p><b>Section:</b> 32.10.7 <a href="https://wg21.link/futures.unique.future">[futures.unique.future]</a> <b>Status:</b> <a href="lwg-active.html#Resolved">Resolved</a>
 <b>Submitter:</b> Alisdair Meredith <b>Opened:</b> 2009-03-12 <b>Last modified:</b> 2021-06-06</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View all other</b> <a href="lwg-index.html#futures.unique.future">issues</a> in [futures.unique.future].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#Resolved">Resolved</a> status.</p>
<p><b>Discussion:</b></p>

<p><b>Addresses UK 335 [CD1]</b></p>

<p>
<code>std::unique_future</code> is <code>MoveConstructible</code>, so you can transfer the
association with an asynchronous result from one instance to another.
However, there is no way to determine whether or not an instance has
been moved from, and therefore whether or not it is safe to wait for it.
</p>

<blockquote><pre>
std::promise&lt;int&gt; p;
std::unique_future&lt;int&gt; uf(p.get_future());
std::unique_future&lt;int&gt; uf2(std::move(uf));
uf.wait(); <span style="color:#C80000">// oops, uf has no result to wait for. </span>
</pre></blockquote>

<p>
Suggest we add a <code>waitable()</code> function to <code>unique_future</code>
(and <code>shared_future</code>) akin to <code>std::thread::joinable()</code>,
which returns <code>true</code> if there is an associated result to wait for
(whether or not it is ready).
</p>

<p>
Then we can say:
</p>

<blockquote><pre>
if(uf.waitable()) uf.wait();
</pre></blockquote>

<p><i>[
Summit:
]</i></p>


<blockquote>
<p>
Create an issue. Requires input from Howard. Probably NAD.
</p>
</blockquote>

<p><i>[
Post Summit, Howard throws in his two cents:
]</i></p>


<blockquote>
<p>
Here is a copy/paste of my last prototype of <code>unique_future</code> which was
several years ago.  At that time I was calling <code>unique_future</code> <code>future</code>:
</p>

<blockquote><pre>
template &lt;class R&gt;
class future
{
public:
    typedef R result_type;
private:
    future(const future&amp;);// = delete;
    future&amp; operator=(const future&amp;);// = delete;

    template &lt;class R1, class F1&gt; friend class prommise;
public:
    future();
    ~future();

    future(future&amp;&amp; f);
    future&amp; operator=(future&amp;&amp; f);

    void swap(future&amp;&amp; f);

    <b>bool joinable() const;</b>
    bool is_normal() const;
    bool is_exceptional() const;
    bool is_ready() const;

    R get();

    void join();
    template &lt;class ElapsedTime&gt;
        bool timed_join(const ElapsedTime&amp;);
};
</pre></blockquote>

<p>
<code>shared_future</code> had a similar interface.  I intentionally reused
the <code>thread</code> interface where possible to lessen the learning
curve std::lib clients will be faced with.
</p>
</blockquote>

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


<blockquote><p>
<del>NAD Editorial</del><ins>Resolved</ins>.  Addressed by
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2997.htm">N2997</a>.
</p></blockquote>



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





</body>
</html>
