std::deque::push_back(3)

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

πŸ’– std::deque::push_back(3) πŸ’–

πŸŽ€ NAME πŸŽ€

std::deque::push_back - std::deque::push_back β€” bestie, this is the C++ Standard Libary manual page for std::deque::push_back, section 3, and it's here to explain the whole append-to-the-end situation πŸ’….

🌸 Synopsis 🌸

void push_back( const T& value ); (1)
void push_back( T&& value );      (2) (since C++11)

It appends the given element value to the end of the container β€” literally yeeting it onto the end 🫢.

  1. The new element is initialized as a copy of value.
  2. value is moved into the new element.

All iterators β€” including the end() iterator β€” are invalidated. No references are invalidated. No cap.

πŸ’œ Parameters πŸ’œ

  • value β€” the value of the element to append.

πŸ¦‹ Type requirements πŸ¦‹

  • T must meet the requirements of CopyInsertable in order to use overload (1).
  • T must meet the requirements of MoveInsertable in order to use overload (2).

πŸŽ€ Return value πŸŽ€

(none) β€” nothing comes back, bestie 😭. It's giving void energy.

πŸ”₯ Complexity πŸ”₯

Constant. Periodt. ✨

πŸ’€ Exceptions πŸ’€

If an exception is thrown β€” and that can be due to Allocator::allocate() or element copy/move constructor/assignment β€” this function has no effect. That's the strong exception guarantee, and yes it's giving safety πŸ’….

✨ Example ✨

       // Run this code

        #include <iomanip>
        #include <iostream>
        #include <string>
        #include <deque>

        int main()
        {
            std::deque<std::string> letters;

            letters.push_back("abc");
            std::string s{"def"};
            letters.push_back(std::move(s));

            std::cout << "std::deque letters holds: ";
            for (auto&& e : letters)
                std::cout << std::quoted(e) << ' ';

            std::cout << "\nMoved-from string s holds: " << std::quoted(s) <<
       '\n';
        }

Possible output:

std::deque letters holds: "abc" "def"
Moved-from string s holds: ""

🌈 See also 🌈

  • emplace_back β€” constructs an element in-place at the end. (C++11) (public member function)
  • push_front β€” inserts an element to the beginning. (public member function)
  • pop_back β€” removes the last element. (public member function)
  • back_inserter β€” creates a std::back_insert_iterator of type inferred from the argument. (function template)

okay that's the whole page! πŸ’– source: http://cppreference.com β€” version/date: 2024.06.10 β€” page: std::deque::push_back(3) 🫢✨

πŸ“¦ where this page comes from