std::array::back(3)
okay bestie, youβre reading the std::array::back(3) page from the C++ Standard Libary manual, and itβs literally all about peeking at the last element. slay π
β¨
π NAME
std::array::back β yes, itβs giving std::array::back, no cap π«Ά
β¨ Synopsis β¨
reference back(); (1) (since C++11)
(constexpr since C++17)
const_reference back() const; (2) (since C++11)
(constexpr since C++14)
It returns a reference to the last element in the container. main character energy π
Warning bestie: calling back on an empty container causes undefined behavior π fr fr, donβt do it.
πΈ Parameters
none, zero, zilch, nada π«Ά
π Return value
A reference to the last element. periodt.
π¦ Complexity
Constant. always. πβ¨
π§ Notes
For a non-empty container c, the expression c.back() is equivalent to *std::prev(c.end()). iykyk πΈ
β Example
The following code uses back to display the last element of a std::array<char>:
// Run this code
#include <array>
#include <iostream>
int main()
{
std::array<char, 6> letters{'a', 'b', 'c', 'd', 'e', 'f'};
if (!letters.empty())
std::cout << "The last character is '" << letters.back() << "'.\n";
}
π Output
The last character is 'f'.
ate, truly πβ¨
π See also
frontβ access the first element (public member function) ππ¦
byeee π this iconic page came from http://cppreference.com, dated 2024.06.10, and itβs the std::array::back(3) page. mwah π«Άπ
π¦ 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