std::forward_list::front(3)
π NAME π
okay bestie, this manual page is std::forward_list::front(3) β the function itself is std::forward_list::front, and it lives in the C++ Standard Libary (that's how the header spells it, no cap). The NAME section is basically std::forward_list::front β std::forward_list::front; yes, it repeats itself, and honestly? iconic. π¦
β¨ Synopsis β¨
Here's the signature lineup, copied exactly:
reference front(); (1) (since C++11)
const_reference front() const; (2) (since C++11)
So it returns a reference to the first element in the container. π
π¨ Warning, bestie: calling front on an empty container causes undefined behavior. That is not a vibe. The page straight-up says it, fr fr. π
π Parameters π
(none)β no arguments, no extra drama. She takes nothing. π
πΈ Return value πΈ
Reference to the first element. That's it. That's the whole return value. β¨
π« Complexity π«
Constant. Fast queen behavior, no cap. π
π§ Notes π§
For a container c, the expression c.front() is equivalent to *c.begin(). iykyk. π«Ά
π Example π
The following code uses front to display the first element of a std::forward_list<char>:
// Run this code
#include <forward_list>
#include <iostream>
int main()
{
std::forward_list<char> letters{'a', 'b', 'c', 'd', 'e', 'f'};
if (!letters.empty())
std::cout << "The first character is '" << letters.front() <<
"'.\n";
}
β Output β
The first character is 'a'.
π¦ See also π¦
push_frontβ inserts an element to the beginning (public member function)pop_frontβ removes the first element (public member function)
xoxo, bestie π β source/version: http://cppreference.com, date: 2024.06.10. Footer info delivered with a bow, because we're cute like that. π
π¦ 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