std::span::front(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ’… 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