It resizes the valarray, changing its size to sz elements, and assigns the value c to each element.
DeclarationFollowing is the declaration for std::valarray::resize function.
void resize (size_t sz, T c = T());C++11
void resize (size_t sz, T c = T());Parameters
sz − It is used to find size of the valarray.
c − It is a value to be assigned to each of the elements of the resized array.
none
ExceptionsBasic guarantee − if any operation performed on the elements throws an exception.
Data racesAll elements effectively copied are accessed.
ExampleIn below example explains about std::valarray::resize function.
#include <iostream> #include <cstddef> #include <valarray> int increment (int x) {return ++x;} int main () { std::valarray<int> myarray (100,50); myarray.resize(3); std::cout << "myvalarray contains:"; for (std::size_t n=0; n<myarray.size(); n++) std::cout << ' ' << myarray[n]; std::cout << '\n'; return 0; }
Let us compile and run the above program, this will produce the following result −
myvalarray contains: 0 0 0
valarray.htm
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4