std::forward_list::reverse(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ’… 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

  • sort sorts 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