Title
Provide empty-state inspection for std::unique_future
Status
resolved
Section
[futures.unique.future]
Submitter
Alisdair Meredith

Created on 2009-03-12.00:00:00 last changed 162 months ago

Messages

Date: 2010-12-05.14:14:49

[ 2009-10 Santa Cruz: ]

NAD EditorialResolved. Addressed by N2997.

Date: 2010-12-05.14:14:49

[ Post Summit, Howard throws in his two cents: ]

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

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

    template <class R1, class F1> friend class prommise;
public:
    future();
    ~future();

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

    void swap(future&& f);

    bool joinable() const;
    bool is_normal() const;
    bool is_exceptional() const;
    bool is_ready() const;

    R get();

    void join();
    template <class ElapsedTime>
        bool timed_join(const ElapsedTime&);
};

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

Date: 2010-10-21.18:28:33

[ Summit: ]

Create an issue. Requires input from Howard. Probably NAD.

Date: 2012-10-21.13:19:07

Addresses UK 335 [CD1]

std::unique_future is MoveConstructible, 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.

std::promise<int> p;
std::unique_future<int> uf(p.get_future());
std::unique_future<int> uf2(std::move(uf));
uf.wait(); // oops, uf has no result to wait for. 

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

Then we can say:

if(uf.waitable()) uf.wait();
History
Date User Action Args
2010-12-05 14:14:49adminsetstatus: nad editorial -> resolved
2010-10-21 18:28:33adminsetmessages: + msg484
2010-10-21 18:28:33adminsetmessages: + msg483
2010-10-21 18:28:33adminsetmessages: + msg482
2009-03-12 00:00:00admincreate