In my class, I have the following declaration:
class OCLState {
//Irrelevant stuff involving OpenCL contexts and command queues and so on...
const cl_int16 values;
OCLState(const std::array<int, 16> & _values);
}
So naturally, I need to initialize the vector when I create this object. Problem is, how do I translate _values into a form that values will accept as an initializer?
OCLState::OCLState(const std::array<int, 16> & _values) : values(
{ _values[0], _values[1], _values[2], _values[3] , _values[4] , _values[5] , _values[6], _values[7],
_values[8], _values[9], _values[10], _values[11] , _values[12] , _values[13] , _values[14], _values[15] }
) {
//Irrelevant stuff involving setting up contexts and queues and so forth
}
This works, but it is EXTREMELY cumbersome and difficult to read. Is there a better way?
EDIT:
OCLState::OCLState(const std::array<int, 16> & _values) : values(array_to_vector(_values)) {
}
cl_int16 OCLState::array_to_vector(const std::array<int, 16> & in) {
cl_int16 out;
for (int i = 0; i < 16; i++) out.s[i] = in[i];
return out;
}
This also works, but I consider it to be non-ideal. I'm looking for a way that doesn't involve writing helper methods for every single vector I might use when writing these programs.