template< class T > /*unspecified1*/ end( valarray<T>& v ); | (1) | (since C++11) |
template< class T > /*unspecified2*/ end( const valarray<T>& v ); | (2) | (since C++11) |
The overload of std::end
for valarray
returns an iterator of unspecified type referring to the one past the last element in the numeric array.
The iterator obtained from this function template is invalidated when the member function resize()
is called on the array v
or when the lifetime of v
ends, whichever comes first.
v | - | a numeric array |
Iterator to one past the last value in the numeric array.
May throw implementation-defined exceptions.
Unlike other functions that take std::valarray
arguments, end()
cannot accept the replacement types (such as the types produced by expression templates) that may be returned from expressions involving valarrays: std::end(v1 + v2)
is not portable, std::end(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.
#include <iostream> #include <valarray> #include <algorithm> int main() { const std::valarray<char> va { 'H', 'e', 'l', 'l', 'o', ',', ' ', 'C', '+', '+', '!', '\n' }; std::for_each( std::begin(va), std::end(va), [](char c) { std::cout << c; }); }
Possible output:
Hello, C++!
(C++11) | overloads std::begin (function template) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/w/cpp/numeric/valarray/end2