std::list::push_back(3)
std::list::push_back(3) π
okay bestie, welcome to the C++ Standard Libary page for std::list::push_back β¨ this function is lowkey iconic: it just yeets a value onto the end of a list, and we're obsessed. no cap, it's giving tiny-but-mighty main character energy π«Ά
π NAME π
std::list::push_back β std::list::push_back. yes bestie, the name really is the name π
β¨ Synopsis β¨
void push_back( const T& value ); (1)
void push_back( T&& value ); (2) (since C++11)
okay so here's the whole vibe: it appends the given element value to the end of the container.
- the new element is initialized as a copy of
value. valueis moved into the new element.
and the part that matters: no iterators or references are invalidated. periodt. π
πΈ Parameters πΈ
valueβ the value of the element to append π
π¦ Type requirements π¦
Tmust meet the requirements ofCopyInsertablein order to use overload (1).Tmust meet the requirements ofMoveInsertablein order to use overload (2).
π Return value π
(none) β literally nothing, bestie, it's voiding in the cutest way π«Ά
π₯ Complexity π₯
Constant. that's it. no extra drama.
π Exceptions π
if an exception is thrown (which can be due to Allocator::allocate() or element copy/move constructor/assignment), this function has no effect β that's the strong exception guarantee, so you can breathe, bestie ππ
π Example π
okay so here's the code, bestie β run it, it's cute:
// Run this code
#include <iomanip>
#include <iostream>
#include <string>
#include <list>
int main()
{
std::list<std::string> letters;
letters.push_back("abc");
std::string s{"def"};
letters.push_back(std::move(s));
std::cout << "std::list 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::list 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 astd::back_insert_iteratorof type inferred from the argument (function template) π¦
xoxo, your Unix bestie π β source: http://cppreference.com, version/date: 2024.06.10, page: std::list::push_back(3) πβ¨
π¦ 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