std::valarray<T>::end
iterator end();
|
(1) | (since C++11) |
const_iterator end() const;
|
(2) | (since C++11) |
Returns an iterator referring to the one past the last element in the numeric array.
The iterator returned from this function is invalidated when the member function resize() is called on v or when the lifetime of v ends, whichever comes first.
Parameters
| v | - | a numeric array |
Return value
Iterator to one past the last element in the numeric array.
Exceptions
May throw implementation-defined exceptions.
Notes
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: (v1 + v2).end() is not portable, std::valarray<T>(v1 + v2).end() 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.
Example
#include <algorithm>
#include <iostream>
#include <valarray>
int main()
{
const std::valarray<char> va
{
'H', 'e', 'l', 'l', 'o',
',', ' ',
'C', '+', '+', '!', '\n'
};
std::for_each(va.begin(), va.end(), [](char c){ std::cout << c; });
}
Output:
Hello, C++!
Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 2058 | C++11 | 1. end() was required to support replacement types2. it was unspecified when the returned iterators will be invalidated |
1. not required 2. specified |
| P3016R6 | C++11 | non-member end() functions introduced inconsistency in range access
|
changed end() to member functions
|
See also
(C++11) |
obtains the beginning iterator of valarray (public member function) |