std::begin(std::valarray)
| template< class T > /*unspecified1*/ begin( valarray<T>& v ); |
(1) | (since C++11) |
| template< class T > /*unspecified2*/ begin( const valarray<T>& v ); |
(2) | (since C++11) |
The overload of std::begin for valarray returns an iterator of unspecified type referring to the first element in the numeric array.
The iterator obtained from this function is invalidated when the member function resize() is called on the array v or when the lifetime of v ends, whichever comes first.
Contents |
[edit] Parameters
| v | - | a numeric array |
[edit] Return value
Iterator to the first value in the numeric array.
[edit] Exceptions
May throw implementation-defined exceptions.
[edit] Notes
Unlike other functions that take std::valarray arguments, begin() cannot accept the replacement types (such as the types produced by expression templates) that may be returned from expressions involving valarrays: std::begin(v1 + v2) is not portable, std::begin(std::valarray<T>(v1 + v2)) has to be used instead.
The intent of this function is to allow range for loops to work with valarrays, not to provide container semantics.
[edit] Example
#include <iostream> #include <valarray> #include <algorithm> auto show = [](std::valarray<int> const& v) { std::for_each(std::begin(v), std::end(v), [](int c) { std::cout << c << ' '; }); std::cout << '\n'; }; int main() { const std::valarray<int> x { 47, 70, 37, 52, 90, 23, 17, 33, 22, 16, 21, 4 }; const std::valarray<int> y { 25, 31, 71, 56, 21, 21, 15, 34, 21, 27, 12, 6 }; show(x); show(y); const std::valarray<int> z { x + y }; std::for_each(std::begin(z), std::end(z), [](char c) { std::cout << c; }); }
Output:
47 70 37 52 90 23 17 33 22 16 21 4 25 31 71 56 21 21 15 34 21 27 12 6 Hello, C++!
[edit] See also
| (C++11) |
specializes std::end (function template) |

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.
