What does the standard specify the behavior of the proxy object of operations on std::valarray?

25 views
Skip to first unread message

xskxzr

unread,
Jan 5, 2018, 11:20:55 PM1/5/18
to ISO C++ Standard - Discussion
Hi all,

[valarray.syn] seems only to say such proxy object should have the same const member functions, and should be able to construct a std::valarray object, but does not say how such functions and constructions work. 

For example, 
valarray<int> a{1, 1};
a
= a + a[0];

Because of the technique of expression template, the compiler may decide to assign a[0] + a[0] to a[0], and then assign a[1] + a[0] to a[1], thus may cause an unexpected result {2, 3}. 

Is this behavior allowed by the standard?

The idea of this question comes from here.

Thanks,
xskxzr
Reply all
Reply to author
Forward
0 new messages