c++ - Cast some elements of std::array to shorter std::array -


is possible cast last 3 elements of std::array<double, 4> std::array<double, 3>?

for example:

void f(std::array<double,3> &); ... int main() {     std::array<double,4> a;     ...     f(/* pass a[1], a[2] , a[3] */); } 

edit:

context: there couple of lattice spin (point) properties computed different functions (different f()-s). functions should populate different parts of array. (array cannot structure because number elements depends on compile-time arguments.) f()-s called millions of times.

there no easier way while keeping function same this:

std::array<double, 3> temp{a[1], a[2], a[3]}; f(temp); 

instead, make function take 2 iterators, , have work more std::array 3 elements:

template<typename iter> void f(iter first, iter last);  f(std::next(std::begin(a)), std::end(a)); 

Comments