◐ Shell
clean mode source ↗

std::span<T,Extent>::begin — cppreference.com

Материал из cppreference.com

<tbody> </tbody>

constexpr iterator begin() const noexcept;

Возвращает итератор на первый элемент span.

Если span - пуст, возвращаемый итератор будет равен end()

Параметры

(нет)

Возвращаемое значение

Итератор на первый элемент.

Сложность

Константная.

Example

#include <span>
#include <iostream>

void print(std::span<const int> sp)
{
    for(auto it = sp.begin(); it != sp.end(); ++it) {
        std::cout << *it << ' ';
    }
    std::cout << '\n';
}

void transmogrify(std::span<int> sp)
{
    if (!sp.empty()) {
        std::cout << *sp.begin() << '\n';
        *sp.begin() = 2;
    }
}

int main()
{
    int array[] { 1, 3, 4, 5 };
    print(array);
    transmogrify(array);
    print(array);
}

Вывод:

See also