std::array::front(3)
πΈ std::array::front(3) π
Bestie, this is the C++ Standard Libary manual page for std::array::front(3) β yes, the header literally spells it βLibary,β and we respect the typo. Itβs giving βfirst element access, but make it const-correct.β
β¨ NAME β¨
std::array::frontβstd::array::front(thatβs it, thatβs the name section, periodt).
π¦ Synopsis π¦
reference front(); (1) (since C++11)
(constexpr since C++17)
const_reference front() const; (2) (since C++11)
(constexpr since C++14)
So overload (1) gives you a reference; overload (2) gives you a const_reference and is const. Both are since C++11, with constexpr since C++17 for (1) and since C++14 for (2).
It returns a reference to the first element in the container.
β οΈ Callingfronton an empty container causes undefined behavior. Not a drill. Do not pass go, do not collect vibes. Checkempty()first if thereβs any chance itβs empty.
π§ Parameters π§
(none) β no args, no stress, literally none.
π Return value π
Reference to the first element.
β Complexity β
Constant. Thatβs the whole complexity section, bestie. No hidden scaling, no side quests.
π§ 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::array<char, 6>. The page literally says // Run this code right before the sample:
#include <array>
#include <iostream>
int main()
{
std::array<char, 6> 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 π
backβ access the last element (public member function).
π okay thatβs the whole page, bestie. Sign-off from the C++ Standard Libary manual: source http://cppreference.com, version/date 2024.06.10, page std::array::front(3). Slay. π
π¦ 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