std::deque::emplace_front(3)

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

πŸ’– std::deque::emplace_front πŸ’–

Okay bestie, welcome to the std::deque::emplace_front page from the C++ Standard Libary (yes, that’s the manual name in the header, spelling and all πŸ’…). This is the C++ Standard Library glow-up for putting a brand-new element at the very front of a std::deque.


🌸 NAME 🌸

std::deque::emplace_front β€” std::deque::emplace_front


πŸ“œ Synopsis

Here’s the signature tea, exactly as written:

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 );

So what does it do? It inserts a new element to 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 at the location provided by the container. The arguments args... are forwarded to the constructor as std::forward<Args>(args)....

And the iterator tea? 🚨 All iterators (including the end() iterator) are invalidated. No references are invalidated. So your references stay safe, but your iterators are absolutely not coming to the function.


🧸 Parameters

  • args β€” arguments to forward to the constructor of the element

🧚 Type requirements

  • T (the container's element type) must meet the requirements of EmplaceConstructible.

🎁 Return value

  • (none) β€” until C++17
  • A reference to the inserted element. β€” since C++17

⚑ Complexity

Constant. Short and sweet, no cap.


πŸ’€ Exceptions

If an exception is thrown for any reason, this function has no effect (strong exception safety guarantee). So if it goes wrong, it’s giving β€œnothing happened here” energy. πŸ’…


πŸ‘€ See also

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

Source: http://cppreference.com Β· version/date: 2024.06.10 Β· page: std::deque::emplace_front(3) β€” bye bestie, go emplace responsibly πŸ’…βœ¨

πŸ“¦ where this page comes from