Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 17
valarray basically allows operation to be done on each element of the array. Hope this example explains everything https://code.sololearn.com/cOF5Q6nTou3T/?ref=app Docs: https://en.cppreference.com/w/cpp/numeric/valarray
11th Feb 2021, 3:22 PM
XXX
XXX - avatar
+ 8
It's an an attempt to make operations on arrays a bit faster by ensuring the fact that everything that would be filled in the array would be a value ( no pointer or refrences ) and perform optimizations accordingly. But as standard evolved ( valarray was introduced in C++98 ) C++ developed much more stronger and powerfull weapons like vectors which provided much wider features with a very little to no performance panelty, making valarrays practically useless. The only difference I see is as pointed by XXX , you can also perform operation on entire array in one go making methamatical operations it a bit easier but practically I can't see any used case where I would be using valarrays instead of any other alternatives like std::array std:: vector etc.
11th Feb 2021, 4:22 PM
Arsenic
Arsenic - avatar
0
An std::valarray<T> is a class (template) container made to process numerical based entities with a specialized manner, it was introduced to manage {int, double, float, et cetera..} by optimizing some programming constraints and relational operation to numerical integrals, by overloading operators and functions. For example : adding two arrays, multiplying, etc.. Also some helper classes (proxy) like slice_array or mask_array for further manipulations. https://code.sololearn.com/cr8rYGl5Sm6e/?ref=app
13th Feb 2021, 1:04 PM
Med Arezki
Med Arezki - avatar
- 1
Hwkksklnejej
13th Feb 2021, 11:04 AM
Muhammad Gidado Saleh