std::forward_list::reverse(3)
π std::forward_list::reverse(3) β C++ Standard Libary manual, section 3
okay bestie, we're in the C++ Standard Libary manual, section 3, and the star of the page is std::forward_list::reverse. it's giving "flip the whole list" main character energy and i'm obsessed π
πΈ NAME
std::forward_list::reverse β std::forward_list::reverse
like... the name is the name, no notes, periodt π
β¨ Synopsis
void reverse() noexcept; (since C++11)
Reverses the order of the elements in the container. No references or iterators become invalidated. so yes, you flip the order and your references/iterators do not get invalidated β the way that's iconic fr fr π¦
π Parameters
(none)
π Return value
(none)
π₯ Complexity
Linear in the size of the container. that's the complexity tea, no cap β¨
π» Example
okay run this code bestie, it's literally the whole demo:
// Run this code
#include <iostream>
#include <forward_list>
std::ostream& operator<<(std::ostream& ostr, const
std::forward_list<int>& list)
{
for (auto& i : list)
ostr << ' ' << i;
return ostr;
}
int main()
{
std::forward_list<int> list = {8, 7, 5, 9, 0, 1, 3, 2, 6, 4};
std::cout << "initially: " << list << '\n';
list.sort();
std::cout << "ascending: " << list << '\n';
list.reverse();
std::cout << "descending:" << list << '\n';
}
π₯οΈ Output
initially: 8 7 5 9 0 1 3 2 6 4
ascending: 0 1 2 3 4 5 6 7 8 9
descending: 9 8 7 6 5 4 3 2 1 0
π See also
sortsorts the elements β public member function
okay that's the whole page, bestie π«Ά source: http://cppreference.com, version/date: 2024.06.10, title: std::forward_list::reverse(3) β slay and bye π
π¦ 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