skip to content
Ivan's wiki
Site Tools
Search
Tools
Show pagesource
Backlinks
Recent Changes
Media Manager
Sitemap
>
Recent Changes
Media Manager
Sitemap
hpp-forward-list
This page is read only. You can view the source, but not change it.
# <forward_list> **[<forward_list>](https://en.cppreference.com/w/cpp/header/forward_list)** is a singly-linked list: fast insertion and deletion at the front (O(1)), but no random access and reverse iteration. It uses less memory than `std::list` and can be faster in practice due to better cache locality. Use it when you need a linked list and only iterate forward; otherwise prefer `std::vector`. This example demonstrates efficient push and pop operations at the front of a forward list. ```cpp // compile: g++ -std=c++11 -o forwardlistexample forwardlistexample.cpp // run: ./forwardlistexample // description: forward_list operations #include <forward_list> #include <iostream> int main() { std::forward_list<int> fl = {1, 2, 3}; fl.push_front(0); std::cout << "after push_front(0): "; for (int x : fl) std::cout << x << " "; std::cout << "\n"; fl.pop_front(); std::cout << "after pop_front: "; for (int x : fl) std::cout << x << " "; std::cout << "\n"; return 0; } ```
Page Tools
Show pagesource
Backlinks
Back to top