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

codekiddy picture codekiddy · Jan 23, 2012 · Viewed 7.3k times · Source

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

Answer

Yakov Galka picture Yakov Galka · Jan 23, 2012
  • 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.