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

Popular posts from this blog

Load Balancing in Bluemix using custom domain and DNS SRV records -

oracle - pls-00402 alias required in select list of cursor to avoid duplicate column names -

python - Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] error -