Namespaces
Variants

std::span<T,Extent>:: end, std::span<T,Extent>:: cend

From cppreference.net

constexpr iterator end ( ) const noexcept ;
(1) (C++20부터)
constexpr const_iterator cend ( ) const noexcept ;
(2) (C++23부터)

* this 의 마지막 요소 바로 다음을 가리키는 반복자를 반환합니다.

이 반환된 반복자는 단지 센티넬 역할만 합니다. 이것이 dereferenceable 하다는 보장은 없습니다.

range-begin-end.svg

목차

반환값

마지막 요소의 다음을 가리키는 반복자.

복잡도

상수.

예제

#include <iostream>
#include <span>
void print(std::span<const int> array)
{
    std::cout << "array = ";
    for (auto it = array.begin(); it != array.end(); ++it)
        std::cout << *it << ' ';
    std::cout << '\n';
}
void set_first_element(std::span<int> sp, int new_value)
{
    if (!sp.empty())
    {
        std::cout << "old *begin = " << *sp.begin() << '\n';
        *sp.begin() = new_value;
        std::cout << "new *begin = " << *sp.begin() << '\n';
    }
}
int main()
{
    int array[]{1, 3, 4, 5};
    print(array);
    set_first_element(array, 2);
    print(array);
}

출력:

array = 1 3 4 5
old *begin = 1
new *begin = 2
array = 2 3 4 5

참고 항목

시작 부분에 대한 반복자를 반환함
(public member function)
(C++11) (C++14)
컨테이너나 배열의 끝 부분에 대한 반복자를 반환함
(function template)