In C++11 and later, std::list::emplace_front() builds a new element directly at the start of a std::list. You pass the constructor arguments, and the object is made inside the new first node.
It is the in-place version of push_front(). Since C++17 it returns a reference to the new element. Include <list> to use it.
This is a member of std::list<T>, a doubly linked list. Every element lives in its own node with a link to the previous and the next node, so a list can insert and erase anywhere quickly once you hold an iterator. It has no access by index, so l[i] does not exist.
Syntax
Call emplace_front with the arguments for the element constructor.
C++
l.emplace_front("Ann", 30); // std::pair<std::string, int>
l.emplace_front(3, '-'); // std::string(3, '-') = "---"
auto& r = l.emplace_front(7); // C++17: reference to the new element
Call
What it does
l.emplace_front(args...)
Builds T(args...) as the new first element.
auto& r = l.emplace_front(args...)
In C++17 and later, the returned reference lets you use the new element at once.
Each new element goes in front of the older ones. The last call to emplace_front() makes the first element of the list.