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

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -