std::deque::front(3)
okay bestie, this is the std::deque::front(3) page from the C++ Standard Libary manual, and itβs short, sweet, and lowkey iconic πβ¨
π NAME π
std::deque::front β std::deque::front
Yes, the name section is literally just the name twice, and honestly? main character energy ππ
β¨ Synopsis β¨
reference front(); (1)
const_reference front() const; (2)
Returns a reference to the first element in the container.
π¨ Calling front on an empty container causes undefined behavior. Not me warning you bestie β do not do that, fr fr ππ
π Parameters π
(none) β zero parameters, not a single one, she takes nothing π
π«Ά Return value π«Ά
Reference to the first element. β thatβs the return value, periodt π«Άβ¨
πΈ Complexity πΈ
Constant. β no cap, thatβs the whole complexity note β¨
π¦ Notes π¦
For a container c, the expression c.front() is equivalent to *c.begin().
Write that down, bestie ππ
π₯ Example π₯
The following code uses front to display the first element of a std::deque<char>:
// Run this code
#include <deque>
#include <iostream>
int main()
{
std::deque<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'.
Ate, honestly πβ¨
π See also π
backβ access the last element (public member function) π¦
okay thatβs the whole page, bestie π«Ά source: http://cppreference.com Β· version/date: 2024.06.10 Β· page: std::deque::front(3) β¨π
π¦ 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