I
Ioannis Vranos
Lionel said:"The class template valarray<T> is a one-dimensional smart array, with
elements numbered sequentially from zero. It is a representation of the
mathematical concept of an ordered set of values. The illusion of higher
dimensionality may be produced by the familiar idiom of computed
indices, together with the powerful subsetting capabilities provided by
the generalized subscript operators.255)".
Elsewhere it is mentioned:
"The expression &a[i+j] == &a + j evaluates as true for all size_t i
and size_t j such that i+j is less than the length of ===> the
non-constant array a. <===
Likewise, the expression &a != &b[j] evaluates as true for any two
==> non-constant arrays <== a and b and for any size_t i and size_t j
such that i is less than the length of a and j is less than the length
of b. This property indicates an absence of aliasing and may be used to
advantage by optimizing compilers.260)".
So as far as I can understand, in the case of the valarray, pointer
arithmetic can be used only for non-constant valarrays.
I find that a bit bizarre. Why should constant valarrays be hamstrung
with regard to potential optimisability? Or is the intention to
facilitate some different/better optimisation (I can't imagine what)
based on const-ness and which might be impeded by imposing the above
restrictions?
I do not know, but I assume they had one or more possible optimisations
in mind. Also valarrays may use "raw memory" and not operator new, among
other things.