I have a function that accepts a const reference to a valarray, and I want to be able to slice the array and pass the slice into another function that expects a const slice_array. I know that I can just use operator[] and a slice to get a new, copied valarray out of the original valarray, but I want to avoid the copy. Everything is const, so I feel like that should be okay. However, the documentation for the subscript operator for valarray ONLY returns a slice_array objects when applied to non-const valarrays. This feels kind of a major deficiency in the valarray class. Am I missing something? How do I get a slice of a const valarray without incurring a copy?
Here is an example of what I'm talking about:
void foo( const valarray<double> &big_stuff )
{
const slice_array<double> small_stuff = big_stuff[slice(start, size, stride)];
bar( small_stuff );
}
Thanks!