std::list::emplace_front(3)
π std::list::emplace_front(3) β the C++ Standard Library glow-up
Okay bestie, so this is the std::list::emplace_front page from the C++ Standard Libary manual β yes it's literally spelled "Libary" up top, we don't talk about it π β and I'm gonna walk you through it like we're texting at 2am. Buckle up, it's giving "niche but iconic."
β¨ NAME β¨
std::list::emplace_front β which is, and I cannot stress this enough, literally std::list::emplace_front. The manual is out here being its own name. Main character energy fr fr. π
πΈ SYNOPSIS πΈ
So the signature has been through a couple eras, like all of us. Watch:
template< class... Args > (since C++11)
void emplace_front( Args&&... args ); (until C++17)
template< class... Args > (since C++17)
reference emplace_front( Args&&... args );
What it does, plain and simple: it inserts a brand new element at the beginning of the container. The element is constructed through std::allocator_traits::construct, which typically uses placement-new to construct the element in-place right at the location the container hands over. The args... get forwarded to the constructor as std::forward<Args>(args).... Chef's kiss. π
And the part that's a whole vibe: no iterators or references are invalidated. None. Zero. Nada. Your iterators are safe, your references are safe, everyone's fine, we love to see it. ππ
π¦ PARAMETERS π¦
argsβ the arguments you're forwarding to the constructor of the element. That's it, that's the parameter. Slay.
π TYPE REQUIREMENTS π
T(the container's element type) must meet the requirements of EmplaceConstructible. No shortcuts, bestie, that's the whole requirement. π
Note: the original page has a lone dash bullet with no text before this item. Consider it the universe's little mystery. π«Ά
β RETURN VALUE β
(none)β until C++17- A reference to the inserted element β since C++17
The glow-up from void to reference is real. Character development. π
π§ COMPLEXITY π§
Constant. O(1) energy. Fast, effortless, unbothered. π₯
π EXCEPTIONS π
If an exception is thrown for any reason, this function has no effect β that's the strong exception safety guarantee. So if things go sideways, it's like it never even happened. We love a clean exit. πβ¨
π SEE ALSO π
push_frontβ inserts an element to the beginning. (public member function) β the classic, the og, the reliable one. π«Ά
That's the whole page, bestie, no notes. Source: http://cppreference.com, version dated 2024.06.10, and we are so grateful for this documentation, fr fr. Go forth and emplace_front responsibly β or don't, I'm a manpage, not a cop. ππβ¨
π¦ 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