C++ std::valarray is the class for representing and manipulating arrays of values. It supports element-wise mathematical operations and various forms of generalized subscript operators, slicing and indirect access.
A valarray object is designed to hold an array of values and easily perform mathematical operations on them. It also allows special mechanisms to refer to subsets of elements in the arrays.
Most mathematical operations can be applied directly to valarray objects, including arithmetical and comparison operators, affecting all its elements.
The valarray specification allows for libraries to implement it with several efficiency optimizations, such as parallelization of certain operations, memory recycling or support for copy-on-reference / copy-on-write optimizations.
std::valarray
and helper classes are defined to be free of certain forms of aliasing, thus allowing operations on these classes to be optimized similar to the effect of the keyword restrict in the C programming language.
Some C++ standard library implementations use expression templates to implement efficient operations on std::valarray
(e.g. GNU libstdc++ and LLVM libc++).
Further details: