Is there a way to make Switch blocks evaluate multiple arguments?

I have three floats, x, y, z, and an enum with 9 possible values. I want to set the enum based on whether each float is >0, <0, or ==0, and this is mechanically simple but a logistical nightmare to do with if blocks. Is there any way I can make a switch block evaluate all three floats simultaneously, something like the following?

		switch (X, Y, Z)
		case (X == 0, Y == 0, Z == 0) :
			myEnum = ESomeEnum::AllZeroes;


As-is it produces a boatload of errors, so I’m assuming this isn’t possible at all, but I thought I would ask. :slight_smile:

Nope, unfortunately that is not a C++ language feature. You’re going to have to use If-statements in this case.

Alright, thanks for the clarification :slight_smile:

imo, the overhead of that would be nasty compared to a simple if statement, but true…

you would have to do this millions of times per tick for it to be a performance bottleneck. none of those operations are expensive. I haven’t tested the performance of this, but i bet its faster than finding the length of a vector. just because a formula takes 3 lines to write doesn’t mean its expensive for a computer to run.

i recommend using whatever method you think will make it easiest for humans to read, and worry about performance when it really counts. the 27 if statements might be easier to read, and might be a fraction of a millisecond faster, but it doesn’t solve the general problem of using a switch case to evaluate multiple states at once.

this may not be the best example, but knowing how to compress multiple values into a single value, which still contains all the information you need, is usually more valuable for saving memory or bandwidth, rather than speeding things up.