2031. std::future<>::share() only applies to rvalues

Section: 33.6.7 [futures.unique_future] Status: C++11 Submitter: Anthony Williams Opened: 2011-02-17 Last modified: 2016-02-10

Priority: Not Prioritized

View all other issues in [futures.unique_future].

View all issues with C++11 status.

Discussion:

As specified, future<>::share() has the signature

shared_future<R> share() &&;

This means that it can only be applied to rvalues. One of the key benefits of share() is that it can be used with the new auto facility:

std::promise<some_long_winded_type_name> some_promise;
auto f = some_promise.get_future(); // std::future
auto sf = std::move(f).share();

share() is sufficiently explicit that the move should not be required. We should be able to write:

auto sf = f.share();

[2011-02-22 Reflector discussion]

Moved to Tentatively Ready after 5 votes.

Proposed resolution:

Alter the declaration of share() to remove the "&&" rvalue qualifier in 33.6.7 [futures.unique_future] p. 3, and 33.6.7 [futures.unique_future] p. 11:

shared_future<R> share() &&;