Your question is a bit confusing, or rather not enough information was provided. It is not clear if the dimsOut[]
variable is needed elsewhere. In case it is used ONLY for the computation of dataSize
, you can use directly the dims[]
array and do:
int typeSize = data->primType().getTypeSize() * data->nDataVar();
int dimension = dims[0] * dims[1] * ((condition) ? dims[2] : 1);
const size_t dataSize = typeSize * dimension;
In case that dimsOut is used elsewhere, then you can use the first block modifying the dimsOut[3] assignment with the ternary operator:
int dimsOut[4];
dimsOut[0] = data->nDataVar();
dimsOut[1] = dims[0];
dimsOut[2] = dims[1];
dimsOut[3] = (condition) ? dims[2] : 1;
const size_t dataSize = data->primType().getTypeSize() * dimsOut[0] * dimsOut[1] * dimsOut[2] * dimsOut[3];