std::end(std::valarray)

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.

# Declarations

template< class T >
/* see below */ end( valarray<T>& v );

(since C++11)

template< class T >
/* see below */ end( const valarray<T>& v );

(since C++11)

# Parameters

# Return value

Iterator to one past the last value in the numeric array.

# 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: std::end(v1 + v2) is not portable, std::end(std::valarray(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.

# Example

#include <algorithm>
#include <iostream>
#include <valarray>
 
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; });
}

# Defect reports

DRApplied toBehavior as publishedCorrect behavior
LWG 2058C++111. end() was required to support replacement types2. it was unspecified when the returned iterators will be invalidated1. not required2. specified

# See also