This may be a stupid question but I have a code with the following line:
Solver *S, *STP = S =
UseDummySolver ? createDummySolver() : new STPSolver(true);
I know the ternary operator but it's the equals signs that confuse me a bit. Can anyone give me some explanation ? Thanks.
Written out, it's
Solver *S;
Solver *STP;
S = UseDummySolver ? createDummySolver() : new STPSolver(true);
STP = S;
It's very ugly though, I'd not recommend doing that in your code.
The recommended way would be to write it as follows (use initialization, rather than assignment):
Solver *S = UseDummySolver ? createDummySolver() : new STPSolver(true);
Solver *STP = S;
I would recommend this:
Solver *S = UseDummySolver ? createDummySolver() : new STPSolver(true);
Solver *STP = S;
It is concise, yet neat and clean.
Also, it uses initialization, rather than assignment. You should prefer initialization over assignment wherever possible.
You're looking at chained assignment.
It is the same as:
Solver *S;
Solver *STP;
S = UseDummySolver ? createDummySolver() : new STPSolver(true);
STP = S;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With