Add future<T>::result_reference()

Issue #150 resolved
Dan Bonachea created an issue

This discussion is copied from implementation issue #268:

John said:

T const& future<T>::result() is a little scary because it could lead to dangling references. Consider:

T const &val = make_future<T>(...).result(); // uh-oh, the future was destroyed

Fortunately the user was sort of asking for it by declaring val a reference. And good news, auto val = (...).result() will infer val's type to be T (non &) regardless if result returns a &-type or not.

Proposal:

I think the proper thing to do is maintain T result() and add T const& result_reference(), where that const& is only added to non-& types.

Adding this feature probably means expanding the future_element<I, T> helper type.

Comments (3)

  1. Log in to comment