Search code examples
c++stdarrayvalarray

What is the difference between std::valarray and std::array


valarray class look's same to array class, can you please explain me where would I prefer valarray over array or vice versa?


Solution

    • valarray was already in C++03, array is new in C++11
    • valarray is variable length, array is not.
    • valarray is designed for numeric computations and provides plenty of operations including +, -, *, cos, sin, etc... array does not.
    • valarray has an interface to retrieve slices of the array (sub arrays), array does not.