(C++17) | ||||
| Sequence | ||||
(C++11) | ||||
(C++26) | ||||
(C++26) | ||||
(C++11) | ||||
| Associative | ||||
| Unordered associative | ||||
(C++11) | ||||
(C++11) | ||||
(C++11) | ||||
(C++11) | ||||
| Adaptors | ||||
(C++23) | ||||
(C++23) | ||||
(C++23) | ||||
(C++23) | ||||
| Views | ||||
(C++20) | ||||
(C++23) | ||||
| Tables | ||||
| Iterator invalidation | ||||
| Member function table | ||||
| Non-member function table |
| Member functions | ||||
| Element access | ||||
(C++26) | ||||
| Iterators | ||||
span::beginspan::cbegin (C++23) | ||||
(C++23) | ||||
(C++23) | ||||
(C++23) | ||||
| Observers | ||||
| Subviews | ||||
| Non-member functions | ||||
| Non-member constant | ||||
| Deduction guides |
constexpr iterator begin()constnoexcept; | (1) | (since C++20) |
constexpr const_iterator cbegin()constnoexcept; | (2) | (since C++23) |
Returns an iterator to the first element of*this.
If*this is empty, the returned iterator will be equal toend().
Contents |
Iterator to the first element.
Constant.
#include <iostream>#include <span> void print(std::span<constint> 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);}
Output:
array = 1 3 4 5old *begin = 1new *begin = 2array = 2 3 4 5
(C++23) | returns an iterator to the end (public member function)[edit] |
(C++11)(C++14) | returns an iterator to the beginning of a container or array (function template)[edit] |