std::span::...pan::cbegin(3)
okay bestie, welcome to the C++ Standard Libary manual β yes, βLibaryβ is literally how itβs spelled in the header, leave it alone π
. Todayβs page is the std::span::...pan::cbegin(3) moment, and itβs all about std::span::begin and std::span::cbegin. iconic behavior only β¨
π NAME π
std::span::begin,std::span::cbegin β literally std::span::begin,std::span::cbegin, no cap.
β¨ Synopsis β¨
constexpr iterator begin() const noexcept; (1) (since C++20)
constexpr const_iterator cbegin() const noexcept; (2) (since C++23)
These two cuties return an iterator to the first element of the span.
If the span is empty, the returned iterator will be equal to end().
Also: range-begin-end.svg β thatβs the little diagram from the original, imagine it right here bestie πΌοΈ.
π«Ά Parameters π«Ά
(none) β literally no parameters, not a single one, zero, zilch, nada. slay.
π Return value π
An iterator to the first element. Thatβs the whole vibe. periodt β¨
π¦ Complexity π¦
Constant. Always constant. No secret extra loops, bestie. fr fr.
πΈ Example πΈ
// Run this code
#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);
}
Output:
array = 1 3 4 5
old *begin = 1
new *begin = 2
array = 2 3 4 5
π See also π
endβ returns an iterator to the endcendβ(public member function)(C++23)begincbeginβ returns an iterator to the beginning of a container or array(C++11)(function template)(C++14)
sending you kisses from http://cppreference.com π, dated 2024.06.10, on the std::span::...pan::cbegin(3) page β bye bestie! π«Ά
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms