Article 6J68W C++ linked-list traversal

C++ linked-list traversal

by
EdGr
from LinuxQuestions.org on (#6J68W)
I am aware of four methods for traversing a doubly-linked list in C++.

Code:// plain c++

for (elem = list.next;
elem != &list;
elem = elem->next) {
}

// macro

FOREACH (elem, list) {
}

// STL

for (elem = list.begin ();
elem != list.end ();
++elem) {
}

// c++11

for (auto& elem : list) {
}I use the "plain c++" method because I have always used that. Consistency is my most important consideration. I am not feeling a need to change.

Which method do you use and why?
Ed
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments