EAxis enum and FVector indexing

I am obviously trying to use the core engine types and structures whenever possible rather than duplicating things unnecessarily, however I was very surprised when I discovered that a bug I had was caused because I’d been wrong in assuming that the EAxis enumeration corresponded to the 0-based index of the components of a vector.

namespace EAxis
{
    enum Type
    {
        None,
        X,
        Y,
        Z,
    }
}

So X is 1, meaning I can’t do the following:

EAxis::Type axis = GetAxisFromSomewhere();
FVector vector = SomeVector;
float component = vector[axis];

There are heaps of times I want to manipulate components based on some runtime dependent axis. If I use EAxis, I need to either remember to add “-1” all over the place, or resort to switching instead leading to code like this.

Then I came across the [FVector::operator code and now I’m really confused. Am I completely off here and writing out hard coded accesses with if-elses is actually faster than the non-branching integer indexing alternative?

Very interested in any reasons or opinions on this.

If you are in performance critical situation then you may want to use VectorRegister to get a proper SSE/NEON vector register and keep all my math work vectorized avoiding going back to scalar floats. If you need to grab just one component use VectorSelect() with the proper mask for the component you want and that will return a vector.

Thanks for your answer @PZurita. I will certainly look into VectorRegister in the future. I’m still a little confused by the 1-based enum, even ignoring performance, since it is just rather inconvenient in the given use case. Anyway I will close the question as it is by no means a major issue.