Where is the good idea to use "std :: valarray"?

I read about std::valarray in a C ++ book written by Nikolai M. Josuttis . He writes in his book The C ++ Standard Library, chapter 17.4:

The valarray classes were not designed very well. In fact, no one was trying to determine if the final specification worked. This happened because no one felt "responsible" for these activities. the people who embed valarrays in the C ++ standard library left the committee long before the standard was finished. As a result, Varjars are rarely used.

So where is the good idea to use std::valarray ?

+8
c ++ c ++ 11 valarray
source share
1 answer

Valarrays are created to allow the compiler to make a faster executable. However, these optimizations are achievable by other means, and varars are rarely used.

std :: valarray and auxiliary classes are defined as free from certain forms of anti-aliasing, which allows optimizing operations on these classes, similar to the effect of restricting a keyword in the programming language C. In addition, functions and operators that accept valarray arguments are allowed to return proxy objects so that the compiler can optimize the expression, such as v1 = av2 + v3; as a single cycle that executes v1 [i] = av2 [i] + v3 [i]; avoiding any temporary or multiple passes ......

In other words, valarrays are intended to be used in places where there are many values ​​that are passed mostly to simple expressions.

Rarely, only valars are optimized, such as Intel Parallel Studio.

Further information can be found at cppreference

+3
source share

All Articles