c++ - Conditional std::future and std::async -
i need conditional behavior.
std::future<int> f = pointer ? std::async(&class::method, ptr) : 0; // ... code x = f.get(); so assign x result async result of ptr->method() call or 0 if ptr nullptr.
is code above ok? can (assign 'int' 'std::futture'? or maybe there better solution?
std::future have no conversion constructor code not valid (as have noticed if tried compile code).
what can use default-constructed future, , check if it's valid before use future.
Comments
Post a Comment