Ich muss bedingtes Verhalten tun.Bedingte Std :: Future und Std :: Async
std::future<int> f = pointer ? std::async(&Class::method, ptr) : 0;
// ... Some code
x = f.get();
So würde Ich mag auf x Ergebnis async Ergebnis ptr->method()
Anruf oder 0 zuweisen, wenn ptr
ein nullptr
ist.
Ist der obige Code in Ordnung? Kann ich so etwas tun (‚int‘ auf ‚std :: futture‘? Zuweisen Oder vielleicht ist es eine bessere Lösung?