#include <forward_list>
#include <iostream>
int main()
{
std::forward_list<int> myList{3};
myList.push_front(0);
myList.push_front(1);
myList.push_front(2);
std::forward_list<int>::iterator iter = myList.begin();
for (int element : myList) std::cout << " " << element;
std::cout << ": ";
std::cout << *iter << " "; iter = ++iter;
std::cout << *iter << " "; iter = ++iter;
std::cout << *iter << " "; iter = ++iter;
std::cout << *iter << " "; iter = ++iter;
std::cout << ": ";
std::cout << myList.front() << " "; myList.pop_front();
std::cout << myList.front() << " "; myList.pop_front();
std::cout << myList.front() << " "; myList.pop_front();
std::cout << myList.front() << " "; myList.pop_front();
std::cout << std::endl;
return 0;
}
// Output: 2 1 0 3: 2 1 0 3 : 2 1 0 3
Reference: https://isocpp.org/wiki/faq/cpp11-library-stl#forward-list
Friday, September 1, 2017
C++11: Containers: forward_list
A singly linked list was added. Here is an example:
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment