- edited description
Add future<T>::result_reference()
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 addT const& result_reference()
, where thatconst&
is only added to non-& types.
Adding this feature probably means expanding the future_element<I, T>
helper type.
Comments (3)
-
reporter -
reporter - changed status to resolved
Add future::result_reference() and future::wait_reference(). Fixes
#150.→ <<cset f1aff266022d>>
-
reporter Merge pull request #27
- const-fixes:
Address comments on PR #27.
Make an equivalence more explicit.
Add newly introduced missing consts.
Add future::result_reference() and future::wait_reference(). Fixes
#150. Add missing consts. Fixes#148.
→ <<cset 43696a1f4dd2>>
- const-fixes:
Address comments on PR #27.
Make an equivalence more explicit.
Add newly introduced missing consts.
Add future::result_reference() and future::wait_reference(). Fixes
- Log in to comment