[cpp-threads] Thread API interface tweaks

Peter Dimov pdimov at mmltd.net
Tue Aug 29 16:17:34 BST 2006


Alexander Terekhov wrote:
> On 8/29/06, Peter Dimov <pdimov at mmltd.net> wrote:
> [...]
>>> enable me to inspect the union
>>> without throwing/catching any exceptions, then I'll be totally
>>> happy.
>>
>> I'm not sure what do you mean by that... can you elaborate?
>
> I basically mean boost::apply_visitor() for boost::variant<
> future_not_ready, future_ready_with_return_value<T>,
> future_ready_with_exception<T>, future_ready_with_exception<U> ...
> X,Y,Z > in future<> object. No?

A future<R> has three states, empty (!ready()), after set_value (has a value 
of type R) and after set_exception. We can add 'bool has_value() const' to 
detect the second. Inspecting the exception type would be tricky, though. 
You typically want to test for the existence of a base class and not for the 
exact type, and the easiest way to do that is to just write the catch clause 
and let the language do its thing. Out of curiosity, why would you want to 
visit the exception instead of catching it? 




More information about the cpp-threads mailing list