
Johan Torp:
Frank Mori Hess wrote:
1) In order to wait on an arbitrary number of futures, determined at runtime, we need some kind of container.
Yes, but it needn't be exposed to users. As you suggested, it can be built up with free functions or expressive templates, similar to Gaskill's comb.
Suppose that the programmer wants to spawn n tasks, where n is not a compile-time constant, and is only interested in whatever task returns a value first. Something like: T f( int x ); // ... vector<future<T>> v; for( int i = 0; i < n; ++i ) { v.push_back( async( f, i ) ); } // wait for any of v[i] to complete, get the T How could this be rephrased with the container being an implementation detail? Here's one way: future<T> ft; for( int i = 0; i < n; ++i ) { ft = ft || async( f, i ); } T t = ft.get(); This however relies on: future<T> operator|| ( future<T>, future<T> ); You can't use 'comb' as the return value.