std::deque::front(3)

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

okay bestie, this is the std::deque::front(3) page from the C++ Standard Libary manual, and it’s short, sweet, and lowkey iconic πŸ’–βœ¨

πŸ’– NAME πŸ’–

std::deque::front β€” std::deque::front

Yes, the name section is literally just the name twice, and honestly? main character energy πŸ‘‘πŸ’…

✨ Synopsis ✨

reference front();             (1)
const_reference front() const; (2)

Returns a reference to the first element in the container.

🚨 Calling front on an empty container causes undefined behavior. Not me warning you bestie β€” do not do that, fr fr πŸ˜­πŸ’€

πŸŽ€ Parameters πŸŽ€

(none) β€” zero parameters, not a single one, she takes nothing πŸ’…

🫢 Return value 🫢

Reference to the first element. β€” that’s the return value, periodt 🫢✨

🌸 Complexity 🌸

Constant. β€” no cap, that’s the whole complexity note ✨

πŸ¦‹ Notes πŸ¦‹

For a container c, the expression c.front() is equivalent to *c.begin().

Write that down, bestie πŸ“πŸ’–

πŸ”₯ Example πŸ”₯

The following code uses front to display the first element of a std::deque<char>:

       // Run this code

        #include <deque>
        #include <iostream>

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

Ate, honestly πŸ“βœ¨

🌈 See also 🌈

  • back β€” access the last element (public member function) πŸ¦‹

okay that’s the whole page, bestie 🫢 source: http://cppreference.com Β· version/date: 2024.06.10 Β· page: std::deque::front(3) βœ¨πŸ’œ

πŸ“¦ where this page comes from