Boost logo

Boost :

Subject: Re: [boost] Non-allocating future-promise
From: Gavin Lambert (gavinl_at_[hidden])
Date: 2014-10-21 01:57:40


On 19/10/2014 14:18, Niall Douglas wrote:
> However, sometimes you will always do:
>
> promise<int> &p;
> auto f=p.get_future().then([]); // always continue
>
> There a memory allocation and std::function wrap is totally
> unnecessary because the compiler has sufficient information to
> construct f statically, except that the present design in N4123
> requires it.
>
> This is what I mean by static continuations - ones which always
> happen unconditionally.

I don't think code like the above would actually occur in the wild. (Or
at least if it did, I would regard it as a bug until proven otherwise.)

There should be no reason to attach a continuation to the future in code
that still has the promise in scope -- it can simply execute that code
directly itself before setting the promise's value.

In "normal" code, the future is returned from a method to outside code
that has no access to the promise, and it is that outside code that
attaches continuations. I don't think that the optimisation you refer
to applies in that case.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk