int input[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
std::valarray<int> test(input, sizeof(input)/sizeof(input[0]));
const std::slice_array<int> s1 = test[std::slice(1, 3, 2)];
const std::slice_array<int> s2 = test[std::slice(0, 3, 1)];
// is it correct to do this?
s1 = s2;
std::valarray<int> temp(s1);
printf("temp[0]=%d temp[1]=%d temp[2]=%d\n", temp[0], temp[1], temp[2]);
Running the code, I got:
test: 0 1 2 3 4 5 6 7 8 9
s1: 1 3 5
s2: 0 1 2
s1=s2
s1: 0 0 2 --> 0 1 2 is expected for s1
test: 0 0 2 0 4 5 6 7 8 9
I'm just wondering if s1 = s2
is correct to use?
If it is correct to use, then is it safe to say that it is a bug for my old version of LLVM C++ library?
Yes, you can assign one
std::slice_array
to another withoperator=
Also, there's no bug here, the result of
s1 = [0, 0, 2]
is correct.In your case:
Notice that the 1st element referred to by
s2
is 0 which gets assigned to the 1st element ofs1
, which is the 2nd element oftest
.This newly assigned value then is the 2nd value of
s2
which gets assigned to the 2nd value ofs1
, and so on.At the end of the assignment,
test
becomes