You can form a link or a pointer to the variable that you want to assign.
(condition ? a : b) = f(x);
The above version was suggested by aschepler in the comments.
*(condition ? &a : &b) = f(x);
The reference version is basically equivalent to the following more detailed example using a helper function.
template <typename T> T& conditional_reference(bool pred, T& yes, T& no) noexcept { return pred ? yes : no; }
I want to say that your traditional if then else thread is probably still the best choice in terms of code clarity.
If the assignment source is a more complex expression than just f(x) , you can save its result in a temporary variable, and then assign this variable only in the conditional expression. The semantics of C ++ 11 relocation in many cases allows the use of such temporary files.
source share