std::span::front(3)
π
std::span::front(3) β C++ Standard Library π
πΈ NAME πΈ
std::span::front β yes bestie, the NAME is literally std::span::front π this is the manual page for std::span::front(3), and we're gonna get into it.
π¦ Synopsis π¦
Here's the whole mood:
constexpr reference front() const; (since C++20)
Returns a reference to the first element in the span.
π¨ Calling front on an empty span results in undefined behavior. Likeβ¦ do not do that, bestie. That's the danger zone. π
π Parameters π
(none)β literally no parameters, no cap π«Ά
π Return value π
A reference to the first element. That's it. That's the whole return value. β¨
π§ Complexity π§
Constant. Literally constant. Iconic behavior, no drama. π
β¨ Notes β¨
For a span c, the expression c.front() is equivalent to *c.begin(). iykyk π¦
π Example π
// Run this code
#include <iostream>
#include <span>
void print(std::span<const int> const data)
{
for (auto offset{0U}; offset != data.size(); ++offset)
std::cout << data.subspan(offset).front() << ' ';
std::cout << '\n';
}
int main()
{
constexpr int data[]{0, 1, 2, 3, 4, 5, 6};
print({data, 4});
}
π Output π
0 1 2 3
π See also π
backβ access the last element (public member function) π
mwah π this page comes from http://cppreference.com, dated 2024.06.10, and the manual page is std::span::front(3) β periodt. π§ββοΈπ
π¦ 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