function template
<iterator> <array> <deque> <forward_list> <list> <map> <regex> <set> <string> <unordered_map> <unordered_set> <vector>

std::end

container (1)
template <class Container>  auto end (Container& cont) -> decltype (cont.end());template <class Container>  auto end (const Container& cont) -> decltype (cont.end());
array (2)
template <class T, size_t N>  T* end (T(&arr)[N]);
container (1)
template <class Container>  auto end (Container& cont) -> decltype (cont.end());template <class Container>  auto end (const Container& cont) -> decltype (cont.end());
array (2)
template <class T, size_t N>  constexpr T* end (T(&arr)[N]) noexcept;
Iterator to end
Returns an iterator pointing to the past-the-end element in the sequence:

(1) Container
The function returns cont.end().
(2) Array
The function returns arr+N.

If the sequence is empty, the returned value compares equal to the one returned by begin with the same argument.

These function templates are defined in multiple headers: Each of these headers includes the generic templates for all container and array types and not simply a specific overload. The headers are: <iterator>, <array>, <deque>, <forward_list>, <list>, map, <regex>, <set>, <string>, <unordered_map>, <unordered_set> and <vector>.

Conversely, end is overloaded (with a different definition) in headers <initializer_list> and <valarray>.

Parameters

cont
An object of a class type for which member end is defined.
arr
An array.

Return Value

For (1), the same as returned by cont.end().
For (2), a pointer to the element that would follow the last element in the array.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// std::begin / std::end example
#include <iostream>     // std::cout
#include <vector>       // std::vector, std::begin, std::end

int main () {
  int foo[] = {10,20,30,40,50};
  std::vector<int> bar;

  // iterate foo: inserting into bar
  for (auto it = std::begin(foo); it!=std::end(foo); ++it)
    bar.push_back(*it);

  // iterate bar: print contents:
  std::cout << "bar contains:";
  for (auto it = std::begin(bar); it!=std::end(bar); ++it)
    std::cout << ' ' << *it;
  std::cout << '\n';

  return 0;
}

Output:
bar contains: 10 20 30 40 50


Data races

The argument is accessed but not modified.
None of the elements in the sequence are accessed by the call, but the iterator returned can be used to access or modify them.

Exception safety

Provides the same level of guarantees as the operation performed on the argument (for standard containers and arrays this is a no-throw guarantee).

See also