...
>
> The alternative is to use valarray as a glorified pointer
> object, and turn it into a real pointer just before you do an
> operation. This requires the compiler to see that
> you've retrieved the pointer from a valarray, realize
> that it is alias-free, and then propagate that knowledge
> through any copies of the pointer you make. Again, it's
> unlikely that any compilers will implement this optimization.
>
> With the restrict keyword, it's very simple to indicate
> that array data is alias-free: one just writes
>
> class Array {
> ...
> double* restrict data;
> };
>
Unfortunately, the fact that the restrict keyword signals the safety of
certain optimizations does not mean the compiler is obligated to
actually perform those optimizations. You can't mandate a code
optimization in a language standard. (It's both politically and
technically infeasible.) I fear that the same compiler vendors that
don't bother to optimize valarray<> also won't bother to make the
restrict keyword anything but a no-op.
In the meanwhile, those few compiler vendors that *do* optimize
valarray<> (Cray?) will probably do so through the use of some
nonstandard keyword such as restrict. The use of this keyword in a
library class will at least hide this language extension from users and
thus improve portability. But it would be better to standardize the
keyword.
It should be understood that valarray<> wasn't proposed until after
restrict was rejected by X3J16. What we couldn't get into the core
language, we hoped to slip into the library. Ain't politics
wonderful?
I hope you all* are beginning to understand some of the back-room
negotiating that goes into hammering out a language standard.
Especially when one tries to standardize existing practice that does
not yet exist.
Kent G. Budge
Sandia National Laboratories
*This is how one does a plural "you" in American English**, Todd. South
of Washington, D.C., it is often contracted to "y'all", but this is regarded
as a charming anachronism (at best) in other parts of the U.S. :-)
**Yes, I'm aware that "American English" is an oxymoron, as well as
possibly insulting to Canadian English speakers (who seem to be constantly
pointing out that they are Americans, too, since Canada is part of North
America, but who speak a slightly different dialect from us southrons), but
I don't know how else to say it. "U.S. English" is clumsy and still an
oxymoron. Simple "American" is also clumsy and remains insulting.
It must be the end of a long week. %-}