I wonder why I cannot compare some_valarray[first_slice] < another_valarray[second_slice]
as I compare some_valarray < another_valarray
and how I can do that in simple way without copying? Of course, I can iterate over them in plain loop but, maybe, there is more elegant and, probably, optimizable way?
Asked
Active
Viewed 291 times
2

George Sovetov
- 4,942
- 5
- 36
- 57
-
As far as I can recall, `valarray` is deprecated. – Lingxi Oct 18 '15 at 08:29
-
@Lingxi could you please provide some proof of that? Tried to google for it but haven't found anything that makes sense. – George Sovetov Oct 18 '15 at 08:31
-
Seems I were wrong. http://stackoverflow.com/questions/2576688/whats-the-future-of-stdvalarray-look-like – Lingxi Oct 18 '15 at 10:38
-
@Lingxi yep, I read that too. – George Sovetov Oct 18 '15 at 10:40
1 Answers
2
To compare a slice_array you currently have to use valarray( const std::slice_array& ).
#include <valarray>
int main() {
//Initialize valarray
std::valarray<int> val0{0,1,2,3,4,5,6,7,8,9};
std::valarray<int> val1{9,8,7,6,5,4,3,2,1,0};
//Compare valarray
std::valarray<bool> cmp0 = val0 < val1;
//Compare slice_array
std::valarray<bool> cmp1 =
std::valarray<int>(val0[std::slice(0,5,2)]) < std::valarray<int>(val1[std::slice(1,5,2)]);
//Compare slice_array since c++17
std::valarray<bool> cmp2 =
std::valarray(val0[std::slice(0,5,2)]) < std::valarray(val1[std::slice(1,5,2)]);
return 0;
}

GKi
- 37,245
- 2
- 26
- 48