[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
CppValarray
Other container classes are e.g. std::vector, std::list and std::map
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
CppValarray
(C++) std::valarray
An STL container class optimized for mathematical operations on sequences. For example, you can square a sequence of values with the example below:class Initializer { public: Initializer() : index(0) {} template <class T> operator()(T& value) { value = index; ++index; } private: int index; }; void myCout(const double& t) { std::cout << t << std::endl; } int main() { std::valarray<double> myArray(10); std::for_each(&myArray[0],&myArray[myArray.size()],Initializer()); std::cout << "After initialization: " << std::endl; std::for_each(&myArray[0],&myArray[myArray.size()],myCout); myArray*=myArray; std::cout << "After 'myArray*=myArray;':" << std::endl; std::for_each(&myArray[0],&myArray[myArray.size()],myCout); }
- include <iostream>
- include <valarray>
- include <algorithm>
Other container classes are e.g. std::vector, std::list and std::map
Topic links
- #include
- scope operator'::'
- stream out operator '<<'
- algorithm (header file)
- argc
- argv
- assert
- char
- class
- cout
- endl
- for_each
- #include
- int
- iostream
- main
- return
- scope operator'::'
- std
- std::cout
- std::endl
- std::for_each
- stream out operator '<<'
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
