skip to content
Ivan's wiki
Site Tools
Search
Tools
Show pagesource
Backlinks
Recent Changes
Media Manager
Sitemap
>
Recent Changes
Media Manager
Sitemap
hpp-valarray
This page is read only. You can view the source, but not change it.
# <valarray> **[<valarray>](https://en.cppreference.com/w/cpp/header/valarray)** provides `std::valarray<T>`, a vector-like container optimized for mathematical operations: elementwise operations, slicing, and masking. Most scientific code uses Eigen or NumPy instead. `valarray` has an odd API and is rarely used in practice. This example performs elementwise addition on two valarrays, demonstrating the vectorized operations this container provides. ```cpp // compile: g++ -std=c++11 -o valarrayexample valarrayexample.cpp // run: ./valarrayexample // description: elementwise valarray operations #include <valarray> #include <iostream> int main() { std::valarray<int> a{1, 2, 3}; std::valarray<int> b{4, 5, 6}; std::valarray<int> c = a + b; std::cout << "sum: "; for (int x : c) std::cout << x << " "; std::cout << "\n"; return 0; } ```
Page Tools
Show pagesource
Backlinks
Back to top