std::forward_list::front(3)

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

πŸ’– NAME πŸ’–

okay bestie, this manual page is std::forward_list::front(3) β€” the function itself is std::forward_list::front, and it lives in the C++ Standard Libary (that's how the header spells it, no cap). The NAME section is basically std::forward_list::front β€” std::forward_list::front; yes, it repeats itself, and honestly? iconic. πŸ¦‹

✨ Synopsis ✨

Here's the signature lineup, copied exactly:

reference front();             (1) (since C++11)
const_reference front() const; (2) (since C++11)

So it returns a reference to the first element in the container. πŸ’…

🚨 Warning, bestie: calling front on an empty container causes undefined behavior. That is not a vibe. The page straight-up says it, fr fr. 😭

πŸŽ€ Parameters πŸŽ€

  • (none) β€” no arguments, no extra drama. She takes nothing. πŸ’–

🌸 Return value 🌸

Reference to the first element. That's it. That's the whole return value. ✨

πŸ’« Complexity πŸ’«

Constant. Fast queen behavior, no cap. πŸ‘‘

🧚 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::forward_list<char>:

       // Run this code

        #include <forward_list>
        #include <iostream>

        int main()
        {
            std::forward_list<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'.

πŸ¦‹ See also πŸ¦‹

  • push_front β€” inserts an element to the beginning (public member function)
  • pop_front β€” removes the first element (public member function)

xoxo, bestie πŸ’œ β€” source/version: http://cppreference.com, date: 2024.06.10. Footer info delivered with a bow, because we're cute like that. πŸŽ€

πŸ“¦ where this page comes from